Expr.h revision 32cf1f27ae8620e7b79bb4e81a067187c0aab7ae
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 2371a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h" 24409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 2531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka#include "clang/Basic/TargetInfo.h" 26f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 28525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 293b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 30b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 31403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 35c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 398e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 40c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 4156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 42409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 45f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 4656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 487ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 49686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 507ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 60ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 61ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Stmt(SC) 62561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 65561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 67f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 68bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 76f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 85905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 868320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 87f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 101ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setValueDependent(bool VD) { 102ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.ValueDependent = VD; 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setTypeDependent(bool TD) { 122ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.TypeDependent = TD; 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 144ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isInstantiationDependent() const { 145ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.InstantiationDependent; 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setInstantiationDependent(bool ID) { 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool containsUnexpandedParameterPack() const { 168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.ContainsUnexpandedParameterPack; 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 176bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 17963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 185026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 186df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1937eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2067eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 210fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 21186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 212077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2132514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 214e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 215e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2187eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 21953202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 22844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 233fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 235ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2384f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2395daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 240ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 24186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2422514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 243e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 244077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 245e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 24844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2601c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 265077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 306ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3072c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3082c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3092c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 311ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 313369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 329369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3450943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3460943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3470943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3480943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 351f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 36456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 36556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 36656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 36856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 38033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 38133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 38233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 38538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 38638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 389f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 390f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 391f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 392093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 393093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 3944919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 3954919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a placeholder type. 3964919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType() const { 3974919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return getType()->isPlaceholderType(); 3984919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 3994919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4004919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a specific placeholder type. 4014919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType(BuiltinType::Kind K) const { 40285def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind(K)); 4034919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 4044919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return BT->getKind() == K; 4054919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return false; 4064919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 407ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 4092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 4102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 4112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 4122b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 413ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 418282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 419282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 420282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 421590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 422590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 424f48fdb0937e67f691393f9ffdf75653e5128ea13Richard Smith bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const; 4250e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith 42670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// isCXX98IntegralConstantExpr - Return true if this expression is an 42770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// integral constant expression in C++98. Can only be used in C++. 42870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const; 42970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith 4304c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// isCXX11ConstantExpr - Return true if this expression is a constant 4314c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// expression in C++11. Can only be used in C++. 432282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 433282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 434282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 4354c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0, 4364c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith SourceLocation *Loc = 0) const; 4374c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith 438745f5147e065900267c85a5568785a1991d4838fRichard Smith /// isPotentialConstantExpr - Return true if this function's definition 439745f5147e065900267c85a5568785a1991d4838fRichard Smith /// might be usable in a constant expression in C++11, if it were marked 440745f5147e065900267c85a5568785a1991d4838fRichard Smith /// constexpr. Return false if the function can never produce a constant 441745f5147e065900267c85a5568785a1991d4838fRichard Smith /// expression, along with diagnostics describing why not. 442745f5147e065900267c85a5568785a1991d4838fRichard Smith static bool isPotentialConstantExpr(const FunctionDecl *FD, 443745f5147e065900267c85a5568785a1991d4838fRichard Smith llvm::SmallVectorImpl< 444745f5147e065900267c85a5568785a1991d4838fRichard Smith PartialDiagnosticAt> &Diags); 445745f5147e065900267c85a5568785a1991d4838fRichard Smith 4460e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// isConstantInitializer - Returns true if this expression can be emitted to 4470e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// IR as a constant, and thus can be used as a constant initializer in C. 4484204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4501e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalStatus is a struct with detailed info about an evaluation in progress. 4511e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalStatus { 45294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 45394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 45494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 456dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// Diag - If this is non-null, it will be filled in with a stack of notes 457dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// indicating why evaluation failed (or why it failed to produce a constant 458dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression). 459dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// If the expression is unfoldable, the notes will indicate why it's not 460dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// foldable. If the expression is foldable, but not a constant expression, 461dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// the notes will describes why it isn't a constant expression. If the 462dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression *is* a constant expression, no notes will be produced. 463dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag; 464dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith 465dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith EvalStatus() : HasSideEffects(false), Diag(0) {} 466e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 467e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 468e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 469e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 470e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 471e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 47294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 47394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4741e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalResult is a struct with detailed info about an evaluated expression. 4751e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalResult : EvalStatus { 4761e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// Val - This is the value the expression can be folded to. 4771e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith APValue Val; 4781e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 4791e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // isGlobalLValue - Return true if the evaluated lvalue expression 4801e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // is global. 4811e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith bool isGlobalLValue() const; 4821e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith }; 4831e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 48451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsRValue - Return true if this is a constant which we can fold to 48551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// an rvalue using any crazy technique (that has nothing to do with language 48651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// standards) that we want to, even if the expression has side-effects. If 48751f4708c00110940ca3f337961915f2ca1668375Richard Smith /// this function returns true, it returns the folded constant in Result. If 48851f4708c00110940ca3f337961915f2ca1668375Richard Smith /// the expression is a glvalue, an lvalue-to-rvalue conversion will be 48951f4708c00110940ca3f337961915f2ca1668375Richard Smith /// applied. 49051f4708c00110940ca3f337961915f2ca1668375Richard Smith bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const; 4915b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 492cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 493cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 494a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// any crazy technique that we want to, even if the expression has 495a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// side-effects. 4964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 497cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 49880d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }; 49980d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith 500a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateAsInt - Return true if this is a constant which we can fold and 50180d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith /// convert to an integer, using any crazy technique that we want to. 50280d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, 50380d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; 504a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith 50551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be 50651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// constant folded without side-effects, but discard the result. 5074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 508c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 5096ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 51051f4708c00110940ca3f337961915f2ca1668375Richard Smith /// which must be evaluated each time and must not be optimized away 5116ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 5126ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 5134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 51451f4708c00110940ca3f337961915f2ca1668375Richard Smith 51551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded 51651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. This must be called on an expression that constant folds to an 51751f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. 518a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const; 51951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 52051f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an 52151f4708c00110940ca3f337961915f2ca1668375Richard Smith /// lvalue with link time known address, with no side-effects. 5224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 5231b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 524099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// EvaluateAsInitializer - Evaluate an expression as if it were the 525099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// initializer of the given declaration. Returns true if the initializer 526099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// can be folded to a constant, and produces any relevant notes. In C++11, 527099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// notes will be produced if the expression is not a constant expression. 528099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, 529099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith const VarDecl *VD, 530099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 531099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith 53282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 53382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 53482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 53582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 53682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 53782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 53882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 53982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 54082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 54182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 54282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 54382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 54482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 54582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 54682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 54782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 548ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 549ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 550ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 551ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 552ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 553ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 554ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 555ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 556ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 557ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 558ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 559ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 560ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 561ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 562ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 56382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 56482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 56582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 56682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 56782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 56882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 569efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 57044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 572102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 57511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 57611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 577864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 578864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 579864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 580864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 581864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 582369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 583369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 584369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 585369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 586369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 587369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 588369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 589369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 590369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 591369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 59291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 59391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 59491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *IgnoreImpCasts(); 59591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 5967e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 5977e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 5987e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); } 5997e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 6004e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 6011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 6024e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 6034e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 6042b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 60556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 60656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 60727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 60856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 610ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off 611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// any ParenExpr or ImplicitCastExprs, returning their operand. 6122fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 6132fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 6142f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 6152f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 6162f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 6172f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 6182f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 6192f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 6202f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 6212f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 6224d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 6234d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 6244d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 626f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 627f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 628f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 630f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 631f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 632f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 6334d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 634ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 635ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 636ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 637ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 6406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 6416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// by semantic analysis for function calls, object constructions, etc. in 6436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 6446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 6456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 6466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 647ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 648558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 649558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 650558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 6512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 65275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 65375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 65491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 65591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall const Expr *IgnoreImpCasts() const { 65691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 65791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 6582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 6594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 6604e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 66156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 66256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 66356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 664ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 665ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 666ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 668898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 669898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 670898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 68456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 68556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 68656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 68756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 68856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 68956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 69056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 69156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 692ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 69356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 694ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 69556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 69656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 697ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie T->isDependentType(), T->isDependentType(), 698561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false), 70056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 70156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 70256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 70356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 70456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 70556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 70656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 70756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 70856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 70956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 71056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 71156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 71256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 71456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 71556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 71656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 71756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 71856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 71956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 72056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 72156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 72256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 72356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 72456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 72556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 72656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 72756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 72856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 72956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 73056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 73156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 73256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 73356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 73456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 73556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 73656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 73756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 73856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 73956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 74056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 74156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 742cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 743cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 744cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 745cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 746cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 747cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 748cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 749cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 750cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 751cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 752cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 753cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 754cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 7553aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 7563aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 7573aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 7583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 759e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// DeclRefExprBits.HasTemplateKWAndArgsInfo: 760cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 761e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// C++ template keyword and/or template argument list. 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 763cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 764cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 7652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 766cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7689e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 769cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 770cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7736857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7746857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7757e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7766857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 777a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 778cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7796857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7806857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7816857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 782a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 783096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7853aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7863aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7893aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7903aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7953aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7963aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7993aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 8003aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 8013aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8023aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8037e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 804e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 8052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 8063aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 8072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 808f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 8092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 810663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 811663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 812663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 8137e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8140da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 8150da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 8160da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 8179e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8195b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, 8205b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 821561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 8225b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 823cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 824e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo = 0; 8253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 8267cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = 0; 8270da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 8280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 830a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 83140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 832e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 833dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 834a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 835f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8363aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 838663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 8392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 84040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 841e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 8422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 8432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 844f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8453aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 8472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 848663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 849663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 8503aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 8513aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 852e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 853def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 8547e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 855cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 856cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 857cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 858904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 8592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 8602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 8612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 8622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8639e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 8640b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 86563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 867a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 868a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 869cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 8707e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8717e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 872a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 873a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 874a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 875a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8767e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8776857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 878a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 87940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8807e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 88140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 88240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 88340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 88440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8857e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8866857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 88740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 88840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8893aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8903aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8953aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8963aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8993aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 9003aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 9013aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 9023aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 9033aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 904e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKWAndArgsInfo() const { 905e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return DeclRefExprBits.HasTemplateKWAndArgsInfo; 906096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9077e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 908e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 909e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 910e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) 911e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 912e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 9133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 914e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 9153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 9163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 9173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 918e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 9193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 9207e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 921e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 922e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 923e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 924e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 925e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 926e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo(); 927e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 928e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 929e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 930e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 931e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 932e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 933e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 934e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 935e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 936e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 937e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 938e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 939e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 940e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 941e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 942e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 943e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 944e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 945e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 946e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 947e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 948e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 949e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 950e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the name in this declaration reference 951e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// was preceded by the template keyword. 952e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 953e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 954e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether this declaration reference was followed by an 955e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 956e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 957e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 958e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the explicit template argument list that followed the 959e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member template name. 960e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 961e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 962e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 963096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9647e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 965096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 966096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 967b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 968096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 969a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 970d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 971096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 972096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 973096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 974e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 975096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 976096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 977096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9787e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 979d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 980d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 981d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 982096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 983096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 984d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 9857e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 986a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 987a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 988833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 989096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 990a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9917e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 992096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 993a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9947e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 995a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 996a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 997a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 998096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 999a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 10007e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1001096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1002a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 10037e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 10047cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this expression refers to a function that 10057cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 10067cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 10077cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return DeclRefExprBits.HadMultipleCandidates; 10087cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 10097cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 10107cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a function that was resolved from an overloaded set having size 10117cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 10127cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 10137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = V; 10147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 10157cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 101799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 102263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10237e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 102460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 10253397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1028d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 1029d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 1030227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 1031227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 1032227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 1033227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 1034848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 1035848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 1036848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 1037848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 1038227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1040227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 1041227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 1042227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 1043227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 1045f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 1046ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie type->isDependentType(), type->isDependentType(), 1047561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 1048bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1049f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 10501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 105317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 105417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1055227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 105617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 105717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 105817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 105917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 106017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1061848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 10623a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 106363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 1064227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1067227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 1068d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 107163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1072227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1073227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 10759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 10769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 10779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 10789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 10799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 10809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 10819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 10829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 10839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 10849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 10859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 10869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 10879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 10889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 10909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 10929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 10939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 10959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 10969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 10989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 10999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 11009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 11019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 11029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 11039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 11059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 11069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 1108ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 1109ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie llvm::APInt getValue() const { return getIntValue(); } 11109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 11119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 11129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 1114ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 111531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka llvm::APFloat getValue(bool IsIEEE) const { 111631dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return llvm::APFloat(getIntValue(), IsIEEE); 111731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka } 11189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 11209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 11229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 11249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 11289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 11299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 11309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 11349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 11359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1136bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1138f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 11401dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 11411dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 11429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1144a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 11451dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 11461dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 11471dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 11481dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 11499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 11509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 11511dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 11529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 11530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 115563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1157313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1158313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1159313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 11609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 11610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11620b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 116963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 11735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 11745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 11755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 11765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 11775cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 11785cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 11795cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 11805cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 11815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 2; 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 11875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 11885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1189bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1190561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11915cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Value(value), Loc(l), Kind(kind) { 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11930b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 11950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 11960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1197018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 11985cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); } 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 12055cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void setKind(CharacterKind kind) { Kind = kind; } 12060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 12070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 121277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 121377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 121463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 12189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 121931dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka bool IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. 1220720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1224720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1225bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1226561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 122731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == 122831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka &llvm::APFloat::IEEEquad), 12299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 12309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 12319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 123317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 123431dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka explicit FloatingLiteral(ASTContext &C, EmptyShell Empty) 123531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka : Expr(FloatingLiteralClass, Empty), 123631dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == 123731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka &llvm::APFloat::IEEEquad), 123831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsExact(false) { } 123917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 12409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 12419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 12429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 12439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 12449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 124531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka llvm::APFloat getValue() const { return Num.getValue(IsIEEE); } 12469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 12479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 12489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 124917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1250720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 125117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1252c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1253da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1254da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1255da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1256da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 125917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 126017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 126163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 126963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 12735d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 12745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 12755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 12765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 12775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 12785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12795d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 12805d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1281bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1282561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1283f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1285cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1287cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1288cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 12895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1291cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1292cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 129363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 12965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 12975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 130063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 13025d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1303e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1304e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1305e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1306a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1307c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1308c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1309690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1310690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 13118bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1312690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1313c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1314c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1315c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1316c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1317c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1318c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 13205cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 13215cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 13225cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 13235cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 13245cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 13255cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 13265cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 13275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 13285cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 13295cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 13303e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 13313e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 133264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman union { 133364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const char *asChar; 133464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint16_t *asUInt16; 133564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint32_t *asUInt32; 133664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } StrData; 133764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned Length; 133864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned CharByteWidth; 1339726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 13405cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 13415cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool IsPascal : 1; 1342726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 13432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1345561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1346561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman static int mapCharByteWidth(TargetInfo const &target,StringKind k); 134964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 13522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 13535cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 135465aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1355a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 13562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 13572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 13585cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 13595cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool Pascal, QualType Ty, 13605cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 13615cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 13622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1363a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1364673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1365673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1366673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1367686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 136864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(CharByteWidth==1 136964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "This function is used in places that assume strings use char"); 137064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(StrData.asChar, getByteLength()); 137164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 137264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 137364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// Allow clients that need the byte representation, such as ASTWriterStmt 137464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// ::VisitStringLiteral(), access. 137564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringRef getBytes() const { 1376e91e0ae772004912285ccc3848b27208da8c045bChris Lattner // FIXME: StringRef may not be the right type to use as a result for this. 1377e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 1378e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(StrData.asChar, getByteLength()); 1379e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 138064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(reinterpret_cast<const char*>(StrData.asUInt32), 138164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman getByteLength()); 1382e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1383e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(reinterpret_cast<const char*>(StrData.asUInt16), 1384e91e0ae772004912285ccc3848b27208da8c045bChris Lattner getByteLength()); 1385b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 13862f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 138764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t getCodeUnit(size_t i) const { 1388e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(i < Length && "out of bounds access"); 1389e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 139064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return static_cast<unsigned char>(StrData.asChar[i]); 1391e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 1392e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt32[i]; 1393e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1394e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt16[i]; 139564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 139664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 139764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getByteLength() const { return CharByteWidth*Length; } 139864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getLength() const { return Length; } 139964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getCharByteWidth() const { return CharByteWidth; } 1400673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1401673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 140264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman void setString(ASTContext &C, StringRef Str, 140364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal); 1404673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 14055cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 1406ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1407ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14085cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 14095cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 14105cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 14115cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 14125cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 14133e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 14145cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 14158d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1416686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1417b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1418b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 141933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 142033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 142133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1422ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1423726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1424726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1425726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1427726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1428726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1429726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1430726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1432673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1433673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1434673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 1435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 143608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 143708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 143808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 143908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 144008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 144108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 144208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 144308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 144408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 144508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1446673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1447b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1448b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1449b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 145977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 146063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 14675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1470898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1471f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1472bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1473561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1474bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1477c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1479c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1480c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 14815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 14825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1483c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1484c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 148563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1487313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1488313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1489c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1490313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1491313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1492313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1493c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1494313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 14991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 150077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 150163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 15060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1508dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1509dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1510dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1511dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1512dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1513dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1514dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15175baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 15185baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 15200799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 15220799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1525f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1526f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1527f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1528de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1529bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (input->isInstantiationDependent() || 1531561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1532bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 15330799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 15345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15350b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 15372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 15380b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15390799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 15400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 15410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 15430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 15440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 15470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 15480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 15502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 15512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 15522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1554cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 15552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 15562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 15572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 15585a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 15590799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 15600799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 15613c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15623c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementOp(Opcode Op) { 15633c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreInc || Op == UO_PostInc; 15643c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 15663c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementOp(getOpcode()); 15673c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15683c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15693c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isDecrementOp(Opcode Op) { 15703c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreDec || Op == UO_PostDec; 15712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15723c3b7f90a863af43fa63043d396553ecf205351cJohn McCall bool isDecrementOp() const { 15733c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isDecrementOp(getOpcode()); 15743c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15753c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15763c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } 15772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 15783c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementDecrementOp(getOpcode()); 15792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15803c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 15822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 15832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15840799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1590bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1591bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1592bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1593bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1594bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1595bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1596bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1597bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 159863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 160463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 161177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 161263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 16168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 16178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 16188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 16198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// double d; 16218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 16228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 16238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 16248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 16258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 16268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 16288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 16308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 16318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 16328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 16338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 16348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 16358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1636cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 16378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1638cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 16398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1640cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1641cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1642cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1643cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1644cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 16458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 16468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 16488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1649ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 16518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1655ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - An unsigned index into the array of Expr*'s stored after this node 16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 16588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 16598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1660ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - A CXXBaseSpecifier*, for references that look at a field in a 1661cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 16628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 16658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1666ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 16678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 16688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 16728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1673ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 16748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 16778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 16788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1679ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 16808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1681cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1682cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1683cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1684cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1687ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Kind getKind() const { 16888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 16898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1690ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 16928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 16938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 16948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 16958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 16968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 16998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 17008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1701cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 17028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1703ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 17058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 17068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1708cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1709cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1710cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1712cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 17158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 17168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 17178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1718ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// contains the location of the period (if there is one) and the 17198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 172006dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 17218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 17228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1724ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 17268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 17278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 17288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 17298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 17308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 17318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1733ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfExpr(ASTContext &C, QualType type, 17348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode* compsPtr, unsigned numComps, 17368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 17378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 17388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 17408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1741ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 17428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *Create(ASTContext &C, QualType type, 1746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode* compsPtr, unsigned numComps, 17488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 17498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 17508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1751ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *CreateEmpty(ASTContext &C, 17528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 17538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 17558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 17568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 17578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 17598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 17608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1761ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 17638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 17648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 17668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 17678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1768ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17698cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 17708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17718cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 17728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 17758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 17778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 17808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 17818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 17848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 17858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 17868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 17878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17888cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 17898cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 17908cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 17918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 17938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 17958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 17968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 17998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 18008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 180263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 18038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 18048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 18078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 18088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 18118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 181363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 181463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 181563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 181663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 181763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 181863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 18208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1821f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1822f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1823f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1824f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1825f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 18260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1827d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1828a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1829d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1830d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 18315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 183242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1834f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1835f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1836f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1837f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1838ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 18392850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1840bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1841561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1842bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1843f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1844a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1845ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1846ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1847f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1848f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1849f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1850f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1851ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1852ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1853bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1854561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1855bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1856f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1857ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1858d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 18590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 18600b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1861f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1862f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 18630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1864f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1865f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1866f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1867f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 18680b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 18700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 18715ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 18725ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1873a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 18740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 18755ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 18760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1877caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 18780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1879d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 18800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1881caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1882f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1883caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 18840b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18850b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1886a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1887a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 18890b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 18900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 18920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 18930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 18940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 18950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 18960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 189776e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 18980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 18990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 19000b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 19010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1902866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 190363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1904866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1905866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 19065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1908f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1910f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 191277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 191363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 192277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19262324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1927f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 192873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1929f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 19302850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1931bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1932561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 1933561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 1934bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1935bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 19362850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 193773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 193873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 193973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1941cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1942cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1943cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1944cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 19452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 19462324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 19472324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 19482324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 19492324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 195033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 195133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 195233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 195333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 19545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 19555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1956cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1957cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 19585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 19595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1960cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 19635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 196477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 19675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 19682324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 19715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 19722324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 19755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 197977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1982026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1983cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1984cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 198563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 19865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 199277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 199363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 199463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 199563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1999b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 2001b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 2003b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 2004b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 20055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 2006cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 20075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 20085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 20095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2011b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 2012cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 2013cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 2014cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 2015cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 2016cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 2017cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2018cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 2019cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2020cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2021cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2022cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 2023cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2024cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2025cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2026cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 2027cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2028cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 2029cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2030cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2031cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 203242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 20335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 2035f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 20361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20371f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 2038ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 20391f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 20405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 20415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 204218b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 2043a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 2044d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 2045d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 2046d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 2047d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 2048d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 2049a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 2050a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 2051bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 2052bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 2053bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2054a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 20555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 20565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2059aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 2060cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 2061cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 2062cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2063d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith const Expr *const *getArgs() const { 2064d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith return const_cast<CallExpr*>(this)->getArgs(); 2065d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith } 2066ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 20685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2070cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 20735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2074cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2077934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 2078934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 2079934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 2080cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 2081934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2083d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 2084d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 2085d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 20868189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 20895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 20901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2091cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 2092cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 2093cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2094cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2095cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 2096cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 2097cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2098cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 2099cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2100cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 21035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 21045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2106cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 2107cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 2108180f47959a066795cc0f409433023af448bb0328Richard Smith unsigned isBuiltinCall() const; 21091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 21111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 21126dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 21136dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2115d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 21161f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2117866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 21182882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21214bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 21224bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 21235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 212588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 212677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 212763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 212863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 212963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 213063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2133ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 21345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 21355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 21366bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 21376857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 21386857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 21396857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 21406857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 21416857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 21426857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 21436857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 2144161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 21456bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 21466bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2147ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2148ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 21495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2151ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2152ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2153f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 21541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2155ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 21592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 21602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 21612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2162ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 216383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 21641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 216583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 21666bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 21676bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2168c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 21696bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 21701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2171e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief True if this member expression specified a template keyword 2172e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// and/or a template argument list explicitly, e.g., x->f<int>, 2173e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// x->template f, x->template f<int>. 2174e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// When true, an ASTTemplateKWAndArgsInfo structure and its 2175e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// TemplateArguments (if any) are allocated immediately after 2176e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the MemberExpr or, if the member expression also has a qualifier, 2177e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// after the MemberNameQualifier structure. 2178e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21807cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief True if this member expression refers to a method that 21817cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 21827cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 21837cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 218483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 21856bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 21866bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 21876bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 218883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 218983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 219083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 21916bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2192c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2193c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2196f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2197f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2198f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2199f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2200ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie base->isTypeDependent(), 2201561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2202561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2203bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 22042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 22052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 2206e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 22077cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) { 22082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 22092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 22102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 22112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 22122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 22132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 2214e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // for constructors, destructors and conversion operators). 22152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2216f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2218f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2219bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2220561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2221bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 22222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 22232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 2224e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 22257cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) {} 2226510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 222840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2229e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2230161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 22312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2232d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2233f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 22365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 223757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 223857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 223957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 224057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 224157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2242f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2243f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 22441f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 22456bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2246161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 22476bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2248161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2249161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 22506bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 22516bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 22526bb8017bb9e828d118e15e59d71c66bba323c364John McCall 22531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 22540979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 22550979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 22566bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 22571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 225983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 226083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 22611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 22626bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 226383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 226540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 226640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 226740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 2268ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the member name was qualified, retrieves the 226940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 227040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 227140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 227240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 227340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 2274ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 227540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 227683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2277c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2278e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2280e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) 2281e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 2282e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2283e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasQualifierOrFoundDecl) 2284e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 2285e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2286e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 2287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getMemberQualifier() + 1); 2288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2290e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2291e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2292e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo(); 2293e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2294e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2295e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2296e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the member name, if any. 2297e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2298e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2299e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2300e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2301e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2302e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2303e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2304e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2305e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2306e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2307e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2308e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2309e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2311e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2312e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2313e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2314c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2316e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 2317e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2318e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2319e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the member name was followed by an 2320e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 2321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2322e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2323d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2324d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2325d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2326096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2327096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2328096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2329096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2330096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2331096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2332096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2333b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2334e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2335e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2336096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2337096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2338096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2339096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2340096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2341b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2342096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2343096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2344096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2345096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2346096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2347096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2348b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2349096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2350096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2351d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2352ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2353c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2354c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2355833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2356e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 23571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2359096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2360c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2362c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2363c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2368096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2369c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 23722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 23732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 23742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 23752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 23762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 23775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 23781f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 23791f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2380ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2381ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2382026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 23831f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 23845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 238575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 2386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 238763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 23885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 238975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 239075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 239175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 239275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 23937cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 23947cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this member expression refers to a method that 23957cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 23967cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 23977cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return HadMultipleCandidates; 23987cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 23997cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 24007cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a method that was resolved from an overloaded set having size 24017cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 24027cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 24037cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates = V; 24047cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 24057cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 24061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 240783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 24085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 24101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24111237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 241263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 24134045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 24144045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 24154045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2419aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2420aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 24210fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 24220fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 24230fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 24240fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 24251d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 24261d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 24271d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 242842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 24295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2430e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2431aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 243242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2433f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2434f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie tinfo->getType()->isDependentType(), 2436bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2437561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2438561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2439bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 244042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2442ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2443ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2444ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2445ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 24465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 24475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2448ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2449e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2450e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2451ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2452ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 24530fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2454ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2455ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 245642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 245742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 245842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 245963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24600fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 24610fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 24620fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 24630fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 246473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 24650fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 246673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2467aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2470aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2471aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24731237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 247463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2475aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2476aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 247749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 247849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 247949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 248049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 24810835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2482cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 24835baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2485cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 24860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2487409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 24881d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2489409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2490f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2491f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2492f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2493f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2494f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2495654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2496654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2497654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2498654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2499654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2500654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 25010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2502f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2503f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2504f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2505898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2506898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2507898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2508898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2509898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2510bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2511ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (ty->isInstantiationDependentType() || 2512561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2513bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2514bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 25158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2516daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 25178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2518654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 25191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2520daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 25211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2522f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 25231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2524087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2525f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 25268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2527654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 25288e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25300835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 25318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 25328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2533f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2534f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 25350835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 25360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2537087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2538087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 25396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 25406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 25416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 25426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 25436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 25446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 25456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 254641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2547f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2548f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 25498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 25508e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2551f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2552f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2553f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2554f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2555f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2556f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 255741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 25581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25594bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 25604bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 25610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 25620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 25631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 256563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 25660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 25670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 256849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 256949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 257049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 257149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 257249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2573bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2574bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2575906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2576bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2577bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2578bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2579bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2580906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 25811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2582906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2583906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2584906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2585906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2586bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2587bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 25880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2589906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2590f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 25915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2592f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 25935baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 259490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2595087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2596f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2597f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2598f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2599f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2600f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2601f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 26025baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2603f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 26045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2605f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2606f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2607f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2608f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 26095baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2610f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2611f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2612087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 261363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 26140835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 26150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 261690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 26171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 261949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 262049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 262149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 262249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 262391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 262491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 262591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 262691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 262791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 262891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 262991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 263049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 26311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 263249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 263349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 263449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 263549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 263649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 263749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 26385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 263949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 264049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 264149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 264249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 264349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2644906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2645906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 26460835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 26479d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 26489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 26499d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 265049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 265149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2652f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2653f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2654f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2655f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 265649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2657db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2658f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2659f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2660db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 266149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 26629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 26639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 26649d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 26659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 26669d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 266749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 266849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 26699d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 267049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26724bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 26734bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 267449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 267549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 267649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 267749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26786eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 267949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 268049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 26816eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2682b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2683b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2684f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2685f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2686f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 268741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2688f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 268941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 269049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2691db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2692f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2693f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2694f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2695f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2696f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2697f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2698f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2699f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2700f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2701f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2702f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2703db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2704b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2705db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2706db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2707b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2708db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2709db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 271063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2711b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 27125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 27155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27166eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 27175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 27203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 27213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 27223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 27233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 27243fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 27253fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 27263fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 27273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 27283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 27293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 27303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 27313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 27323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 27333fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 27343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 27353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 27363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 27375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 27385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 27395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 27405baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 274117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 27420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 27430799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 27440799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 274517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 27465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 274917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2750f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 275117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2752f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2753898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2754bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2755561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2756561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2757bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2758bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2759898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 27601237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27611237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 27635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 27645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2766db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 27682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2769db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27702def77399ab3088106a2d61372344f5b7104e1a2David Blaikie SourceLocation getExprLoc() const { return OpLoc; } 277117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2772db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2773db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27740799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2775db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2776db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2778db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 27795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2780db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2781db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 278263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 27835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 27845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 27875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 27885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 27895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27900799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2791a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2792063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2793063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2794063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2795063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2796063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2797063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2798063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2799063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 28005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2801200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 28022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 28032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 28040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 28052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 28060799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2807aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 28082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 28090799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2810f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 28112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 28120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2813f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 28142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 28150799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 28180799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2819aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 28202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 28210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2822f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 28230e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 28240e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 28250e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 28260e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 28270e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 28280e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 28292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 28302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 28310e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 28320e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 28330e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 28344b9c2d235fb9449e249d74f48ecfec601650de93John McCall static Opcode getOpForCompoundAssignment(Opcode Opc) { 28354b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(isCompoundAssignmentOp(Opc)); 2836b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall if (Opc >= BO_AndAssign) 2837b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); 28384b9c2d235fb9449e249d74f48ecfec601650de93John McCall else 28394b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); 28404b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 28410e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 28420e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 28432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 28442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 28450e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 28460e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 28470e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 28481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 28504bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 28514bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 28525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 28541237c673c07f9d827129ba02720108816abde562Ted Kremenek 28551237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 285663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 285763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 285863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 28591237c673c07f9d827129ba02720108816abde562Ted Kremenek 28605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 286117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2862f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 28632333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2864f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 28652333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2866bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2867561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2868561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2869bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2870bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 28712333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 28721237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 28731237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 28745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2875ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 28772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 28785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 28815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 2882ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 28835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 28845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 28855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 28865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2887ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2888ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 28895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2890f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2891f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2892f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 289317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2894f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2895ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2896ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 28985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 28995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2901ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2902ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2903ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2904ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2905ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2906ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2907ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2908ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2909ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2910ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2911ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2912ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2913ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 29145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 29151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 29161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 29175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 29195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 292056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 292156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 292256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 292356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 292456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 292556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 292656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 292756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 292856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 2929561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 293056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 293156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 293256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 2933561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 293456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 293556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 293756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 293856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 294056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 294156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 294256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 294356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 294556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 294656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 294756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 294956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 295056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 295156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 295256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 295356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 295456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 295556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 295656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 295756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 295856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 295956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 296056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 296156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 296256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 296356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 296456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 296556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 29661237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 29675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 296856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 296956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 29705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 297147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 297256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 29730943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 297456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2977898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 297856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 297956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 298056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2981561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 2982561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 2983561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2984bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 298556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 298656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 298756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 29881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 29891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 29901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 29911237c673c07f9d827129ba02720108816abde562Ted Kremenek } 29925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2993ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2994ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 299556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2996ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2997395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 299856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 29995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 3000395a2abf0028968d85958610e393e067885dc14fTed Kremenek 300156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 300256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 300356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 300556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 300656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 300756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 30085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 3009ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 301056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 30115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 301247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 301363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 30155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 30185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 30201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30211237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 302263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 302363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 302463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 30255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 30265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 302756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 302856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 302956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 303056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 303156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 303256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 303356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 303456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 303556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 303656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 303756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 303856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 303956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 304056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 304156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 304256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 304456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 304556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 304656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 304756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 304856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 304956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 305056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 305156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 3052561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 3053561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 305456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 305556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 305656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 305756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 305856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 305956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 306056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 306156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 306256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 306356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 306456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 306556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 306656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 306756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 306856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 306956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 307056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 307156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 307256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 307356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 307456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 307556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 307656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 307756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 307856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 307956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 308056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 308156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 308256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 308356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 308456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 308556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 308656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 308756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 308856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 308956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 309056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 309156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 309256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 309356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 309456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 3095ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 309656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 309756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 309856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 309956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 310056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 310156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 310256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 310356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 310456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 310556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 310656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 310756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 310856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 310956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 311056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 311156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 311256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 311356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 311456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 311556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 311656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 311756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 311856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 311956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 312056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 312156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 312256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 312356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 312456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 312556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 312656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 312756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 31286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 31296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 31305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 3131ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 31325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3133ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 31346481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 3135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 3136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 31372333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 31401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 31417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 31427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 31437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 31447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 31457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 31467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 31477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 314863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 31505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3152ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3153ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 31547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 31555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 31561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 31575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 31586481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31601237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 316163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 31625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3163ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3164ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3165ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3166ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3167f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3168f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3169f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3170ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 31715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3172ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3173ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 31742333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3176561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3177d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3178d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3179f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3180561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 31812333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 31846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 31856a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 31865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 31875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 31886a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 31896a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 319063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3191ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 3192ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 31931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3194026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 31956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3196026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 31976a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3199ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3201ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 3202ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 32031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32041237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 320563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3206ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3207ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3208d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3209d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3210d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3211d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3212d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3213d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3214d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3215d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3216d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3217d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3218d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3219d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3220d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3221d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 32225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3223d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3224d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3225d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3226a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 32271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3228bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 322994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 323094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 32311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 323294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 323394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 323494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 323594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 32361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 323794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 323894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 323994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 324063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3241d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3242d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3243d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3245d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3246d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 32471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3248d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3249d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3250d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3251d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 32521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3253aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3254aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3255ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3256d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3257d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3258d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 32595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3260d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3261d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3262d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 32635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3264d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 32651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3266888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 326794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3268dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3269dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 3270a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue(); 3271d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 32721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3273d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 327463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 327563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 327663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3277d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3278d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3279d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3281d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 32827976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 32837976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 32847976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 32857976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 32867976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 32877976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3288d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 32891237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 32905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3291d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3292d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3293f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3295ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3296bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3297561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3300bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3301bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3302bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 33031237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 33041237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 33051237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 33061237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 33071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 33087976932a1c256d447316ffac58e9821417725e34Eli Friedman 330944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 331044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 331144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 33127976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 33137976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 33144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 33157976932a1c256d447316ffac58e9821417725e34Eli Friedman 33167976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 33177976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 33184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 33197976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 33207976932a1c256d447316ffac58e9821417725e34Eli Friedman } 33217976932a1c256d447316ffac58e9821417725e34Eli Friedman 33225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 332344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 33245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 332544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 33265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 332744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 332844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 332944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 333044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 333244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 333344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 33341237c673c07f9d827129ba02720108816abde562Ted Kremenek 333563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3336d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3337d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3338d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3340d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3341d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 33421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33431237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 334463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 334563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 334663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3347d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3348d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 33492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 33502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 33512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 33522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 33532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 33542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 33552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 33562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 33572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 33582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 33592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 33601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3361561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3362561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 33642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 336544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 336644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 336744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 33682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 33692d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 337044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 33712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 337263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 33732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 33742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 33752d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 33761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 33772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 33782d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 338163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 33822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 33832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 338474626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 33857c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 33865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 33872cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 33887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 33897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 33902cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 33912cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3392f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3393bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3394561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3395561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3396bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3397bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 33982cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 33997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 34007c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 340274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3403d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3404d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 34055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 34065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3407d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3408d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 34092cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 34102cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 34112cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3412d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3413d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 34141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3415d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3416d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3417d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 341863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 34197c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 34201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 34217c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 34227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 34237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 34247c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 34251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 342763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 34287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 34291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 34314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 34324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 34334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 34344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 34354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 34364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 34374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 34384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3439196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 34404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 34414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 34424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 34434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 34444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 34454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 34464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 34474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3448196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 34494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 34504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 34514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 34524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 34534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 34544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 34554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 34563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 34574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 34584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 34594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3460196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 34614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 34624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 34634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 34644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 34654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 34664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 346766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3468ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3469709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3470709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 347166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 34721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 34744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 34754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 34764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 34774423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 34784423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 34794423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 34804423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 34814423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 34824423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 34834423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 34844423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 34850bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 348666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3487709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3488709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3489ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3490d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3491d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3492709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3493709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 34941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3495ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 34961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3497aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3498aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 350016c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3501c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 35024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 350366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 35041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 350516c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3506c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 35074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 350866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 35091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3511c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 35129e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 35139e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3514c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3515fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3516709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 35171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 35194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 35204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 35214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 35224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 35234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 35244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 35254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 35264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 35274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 35284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 35294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 35304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 35314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3532fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3533709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3534c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 35354423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 35364423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 35374423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 35384423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 35394423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 35404423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 35418cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 35428cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 35438cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 35443e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 35454423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 354621f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// \brief Return true if this is an array initializer and its array "filler" 354721f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// has been set. 354821f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis bool hasArrayFiller() const { return getArrayFiller(); } 354921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis 35500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 35510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 35520bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 35530bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 35540bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 35550bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 35564423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 35574423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 35584423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 35598cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 35608cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 35618cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 35624423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 35634423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 35644423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 35650bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3566c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3567c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3568b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3569b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3570b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 35711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3572d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3573d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3574d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 357587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 357687fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 35774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 35784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 35794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 35801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 35814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 35824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 35834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 358432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl bool hadArrayRangeDesignator() const { 358532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl return InitListExprBits.HadArrayRangeDesignator != 0; 358632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 358832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBits.HadArrayRangeDesignator = ARD; 358932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 359032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 359132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl bool initializesStdInitializerList() const { 359232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl return InitListExprBits.InitializesStdInitializerList != 0; 359332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 359432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl void setInitializesStdInitializerList(bool ISIL = true) { 359532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBits.InitializesStdInitializerList = ISIL; 3596a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3597a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 359863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3599c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 360066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 36011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 360266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 360366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 36041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 360566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 360663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 360763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 360863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 360963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 36101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3611709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 36128111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3613709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 36148111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3616ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 36178111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3618ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 36198111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3620ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 36218111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3622ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 36238111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 36244423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 36254423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 36264423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 362766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 362866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 362905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 363005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 363205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 363505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 36361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 363705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 363805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 363905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 364205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 364305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 364405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 364505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 364605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 364805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 364905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3650ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3651ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3652ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3653ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3654ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 365705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3659eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 366005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3661eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 366205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 366305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 366405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 366505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3666ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3667ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3668ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3669ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 367005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 367105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 367205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 367305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 367405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3675ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3676319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3677ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3678eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 36799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 36809ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3682d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3683d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3684d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3685d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 368605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 368705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 368805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 368905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 369005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 369105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 369205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 369305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 369505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 36961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 369705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 369805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 36991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 370105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 370205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 370305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 370405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 370505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 370605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 370705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 370805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 370905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 371005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 371105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 371205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 371305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 371405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 37151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 371605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 371705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 371805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 371905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 372005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 372105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 372205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 372305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 372405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 372505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 372605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 372705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 372805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 372905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 373005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 373705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3741ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3742ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 37441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 37451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 37531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 375405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 375505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 375605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 375705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 375805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 375905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 376005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 376105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 376205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 37631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 376405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 376505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 376605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 376705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 376805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 376905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 377005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 377105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 377205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 377305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 377405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 377505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3776b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 377705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3778b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 377905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 378005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 378105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 378205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 378305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 378405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 378505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 378605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 378705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 378805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 378905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 379005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 379187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 379287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 379387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 379487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 379587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 379605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 379705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 379805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 379905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 380005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 380105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 380205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 380305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 380405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 380505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 380605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 380705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 380805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 380905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 381005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 381105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 381205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 381305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 381405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 381505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 381605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 381705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 38184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3819d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3820d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3821d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3822d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3823d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3824d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 38254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 38264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 38274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 38284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 38294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 38304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 383124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 383224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 383324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 383424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 383524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 383624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 383705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 383805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 38391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 384005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 384105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 384205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3843eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 384405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3845d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3846d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 384705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 384805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 384905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 385005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3851b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3852ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 38531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 38541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3855ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 385605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3857b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3858b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3859b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3860b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3861b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3862b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3863cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3864cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3865cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3866cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3867cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3868cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3869cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3870cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3871cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3872b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3873b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3874b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3875b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3876b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3877b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3878b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3879b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3880b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3881711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3882711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setDesignators(ASTContext &C, const Designator *Desigs, 3884319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3885d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 388605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 388705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 388805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 388905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 389005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 389105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 389205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3893d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 389405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 389505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3896eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3897eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3898d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 389905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 390005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 39011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 390205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 390305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 390405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 390505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 390605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 390705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 390805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3909d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3910d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3911d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3912d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3913d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3914d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3915d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3916d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3917d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3918d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3919d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3920d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3921d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3922d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3923d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3924d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3925d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3926d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3927d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3928d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3929ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3930ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3931319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3932ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3933ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 393424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 393524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 393663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 393705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 393805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 39391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 394005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 394105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 394205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 394305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 394463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 394563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 394663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 394763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 39483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 39493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 39503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 39513498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 39523498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 39531a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 39541a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 39553498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 39561a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 39571a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 39581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 39593498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 39601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3961f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3962561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 39633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3964d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3965d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3966d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3967d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 39681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 39693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 39703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 39713498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 39723498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 397363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 39743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 39753498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 39763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 39773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 397863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 397905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 398005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 39812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 39832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 39842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 39852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 39862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 39881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 39895b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl unsigned numexprs, SourceLocation rparenloc); 39902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 399237bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 39931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39942ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 39951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 39972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 39982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 39992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 40001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 40022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 40032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 40042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 40052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 400683ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 40071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 40092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 40102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 401163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 40122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 40131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 40142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 40151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 40162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 40172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 40181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 402063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 402163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 402263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 402337bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 402460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 40253397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 40262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 40272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 40281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4029ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// \brief Represents a C11 generic selection. 4030f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4031ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling 4032f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 4033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 4034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 4035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 4036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 4037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 4038f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 4039f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 4040f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4041f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 4042f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 4043f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 4044f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4045f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 4046f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 4047f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4048f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 4049f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 4050f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4051f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 4052f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 4053f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 4054f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 4055f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 4056f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 4057f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 4058f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 4059f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 4060f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 4061f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4062f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 4063f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 4064f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 4065f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 4066f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 4067f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 4068f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 4069f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 4070f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4071f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 4072f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 4073f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 4074f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 4075f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 4076f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 4077f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 4078f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4079f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 4080f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 4081f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4082f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 4083f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4084f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 4085f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 4086f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 4087f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4088f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 4089f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 4090f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4091f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 4092f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4093f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 4094f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 4095f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4096f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 4097f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4098f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 4099f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 4100f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 4101f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 4102f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 4103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4104f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4105f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 4106f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 4107f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4108f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 4109f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4110f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 4111f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 4112f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4113f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 4114f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 4115f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4116f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 4117f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 4118f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 4119f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4120f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4121f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 4122f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4123f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 4124f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 4125f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4126f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 4127f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 4128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4129f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 4130f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 4131f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4132f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 4133f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4134f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 4135f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 4136f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4137f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4138f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 4139f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 4140f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 41414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 41424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 41434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 41444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 4145a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4146a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 4147a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 4148a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 4149a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 415073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 415173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 415273525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 4153a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 4154a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 4155d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4156a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4157a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4158f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 41600943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 41610943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4164bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4165d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 41661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4167d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4168d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4169d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4170d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4171a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4172a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4173d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4174d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4175d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4176d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4177d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4178d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4179d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4180d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4181a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4182a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 41831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4184a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4185a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4186a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 41871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4188a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4189a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4190686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 419263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4193a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 4194a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 41951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41962140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 41972140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 41982140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 41991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4202a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 4203a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 42041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4205a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 420663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4207a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4208a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4209a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 421056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 42119c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 42124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 421356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 421456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 42154eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4216469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4218ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ty->isDependentType(), false, 4219561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Check for instantiate-dependence in the statement? 4220561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isInstantiationDependentType(), 4221561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4222469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 42239c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 422484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 422584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 422684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4227d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 422856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 422984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 423084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 423156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 423256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 423356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 423456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 42359c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 423663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 423756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 42389c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 42399c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 424056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 4241a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall const FunctionProtoType *getFunctionType() const; 424256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 42431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42449c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 42454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 42464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 42471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 424963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 42504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 42511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42526b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 42536b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 42544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 42556b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 42564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 42577d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 42587d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 42594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 42606b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 42616b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 426294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 426394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 426494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 426594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 426694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 42671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42686b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 42696b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 42706b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 427194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 427294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 427394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 427494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 427563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 42761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 427894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 42791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42807d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 42817d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 4282ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 42854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 42864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 42871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 428963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 42904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 42914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 429261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 429361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 429461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 4295379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 429661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4297379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 429861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4299379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4300379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4301379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4302379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 4303ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 430461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 430561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 430661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 430761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4308ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(AsTypeExprClass, DstType, VK, OK, 4309561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4310561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4311561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4312561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4313561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4314561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4315379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 4316ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 431761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4318379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4319379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4320379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4321379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4322379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4323379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4324379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 4325ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 43267b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 432761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 432861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 4329ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 433061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 4331ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return T->getStmtClass() == AsTypeExprClass; 433261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 433361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 4334ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 433561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4336379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 433761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 4338276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 43394b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr - An expression which accesses a pseudo-object 43404b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// l-value. A pseudo-object is an abstract object, accesses to which 43414b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// are translated to calls. The pseudo-object expression has a 43424b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// syntactic form, which shows how the expression was actually 43434b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// written in the source code, and a semantic form, which is a series 43444b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// of expressions to be executed in order which detail how the 43454b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// operation is actually evaluated. Optionally, one of the semantic 43464b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// forms may also provide a result value for the expression. 43474b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 43484b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// If any of the semantic-form expressions is an OpaqueValueExpr, 43494b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// that OVE is required to have a source expression, and it is bound 43504b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// to the result of that source expression. Such OVEs may appear 43514b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// only in subsequent semantic-form expressions and as 43524b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// sub-expressions of the syntactic form. 43534b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 43544b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr should be used only when an operation can be 43554b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// usefully described in terms of fairly simple rewrite rules on 43564b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// objects and functions that are meant to be used by end-developers. 43574b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// For example, under the Itanium ABI, dynamic casts are implemented 43584b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// as a call to a runtime function called __dynamic_cast; using this 43594b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// class to describe that would be inappropriate because that call is 43604b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// not really part of the user-visible semantics, and instead the 43614b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// cast is properly reflected in the AST and IR-generation has been 43624b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// taught to generate the call as necessary. In contrast, an 43634b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// Objective-C property access is semantically defined to be 43644b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// equivalent to a particular message send, and this is very much 43654b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// part of the user model. The name of this class encourages this 43664b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// modelling design. 43674b9c2d235fb9449e249d74f48ecfec601650de93John McCallclass PseudoObjectExpr : public Expr { 43684b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions. 43694b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Always at least two, because the first sub-expression is the 43704b9c2d235fb9449e249d74f48ecfec601650de93John McCall // syntactic form. 43714b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43724b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.ResultIndex - The index of the 43734b9c2d235fb9449e249d74f48ecfec601650de93John McCall // sub-expression holding the result. 0 means the result is void, 43744b9c2d235fb9449e249d74f48ecfec601650de93John McCall // which is unambiguous because it's the index of the syntactic 43754b9c2d235fb9449e249d74f48ecfec601650de93John McCall // form. Note that this is therefore 1 higher than the value passed 43764b9c2d235fb9449e249d74f48ecfec601650de93John McCall // in to Create, which is an index within the semantic forms. 43774b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Note also that ASTStmtWriter assumes this encoding. 43784b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43794b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); } 43804b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr * const *getSubExprsBuffer() const { 43814b9c2d235fb9449e249d74f48ecfec601650de93John McCall return reinterpret_cast<const Expr * const *>(this + 1); 43824b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43834b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43844b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; 43854b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43864b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(QualType type, ExprValueKind VK, 43874b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntactic, ArrayRef<Expr*> semantic, 43884b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 43894b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43904b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); 43914b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43924b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSubExprs() const { 43934b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.NumSubExprs; 43944b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43954b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43964b9c2d235fb9449e249d74f48ecfec601650de93John McCallpublic: 43974b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// NoResult - A value for the result index indicating that there is 43984b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// no semantic result. 43994b9c2d235fb9449e249d74f48ecfec601650de93John McCall enum { NoResult = ~0U }; 44004b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44014b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic, 44024b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantic, 44034b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 44044b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44054b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell, 44064b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs); 44074b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44084b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the syntactic form of this expression, i.e. the 44094b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expression it actually looks like. Likely to be expressed in 44104b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// terms of OpaqueValueExprs bound in the semantic form. 44114b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; } 44124b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; } 44134b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44144b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the index of the result-bearing expression into the semantics 44154b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expressions, or PseudoObjectExpr::NoResult if there is none. 44164b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getResultExprIndex() const { 44174b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) return NoResult; 44184b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.ResultIndex - 1; 44194b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44204b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44214b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the result-bearing expression, or null if there is none. 44224b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getResultExpr() { 44234b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) 44244b9c2d235fb9449e249d74f48ecfec601650de93John McCall return 0; 44254b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex]; 44264b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44274b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getResultExpr() const { 44284b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getResultExpr(); 44294b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44304b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44314b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } 44324b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44334b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef Expr * const *semantics_iterator; 44344b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef const Expr * const *const_semantics_iterator; 44354b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_begin() { 44364b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 44374b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44384b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_begin() const { 44394b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 44404b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44414b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_end() { 44424b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 44434b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44444b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_end() const { 44454b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 44464b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44474b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSemanticExpr(unsigned index) { 44484b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(index + 1 < getNumSubExprs()); 44494b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[index + 1]; 44504b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44514b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSemanticExpr(unsigned index) const { 44524b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); 44534b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44544b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44554b9c2d235fb9449e249d74f48ecfec601650de93John McCall SourceLocation getExprLoc() const { 44564b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getExprLoc(); 44574b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44584b9c2d235fb9449e249d74f48ecfec601650de93John McCall SourceRange getSourceRange() const { 44594b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getSourceRange(); 44604b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44614b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44624b9c2d235fb9449e249d74f48ecfec601650de93John McCall child_range children() { 44634b9c2d235fb9449e249d74f48ecfec601650de93John McCall Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer()); 44644b9c2d235fb9449e249d74f48ecfec601650de93John McCall return child_range(cs, cs + getNumSubExprs()); 44654b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44664b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44674b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const Stmt *T) { 44684b9c2d235fb9449e249d74f48ecfec601650de93John McCall return T->getStmtClass() == PseudoObjectExprClass; 44694b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44704b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const PseudoObjectExpr *) { return true; } 44714b9c2d235fb9449e249d74f48ecfec601650de93John McCall}; 44724b9c2d235fb9449e249d74f48ecfec601650de93John McCall 4473276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 4474276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 4475276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// similarly-named C++0x instructions. All of these instructions take one 4476276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// primary pointer and at least one memory order. 4477276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr { 4478276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4479276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum AtomicOp { Load, Store, CmpXchgStrong, CmpXchgWeak, Xchg, 44807a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall Add, Sub, And, Or, Xor, Init }; 4481276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate: 4482276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, END_EXPR }; 4483276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Stmt* SubExprs[END_EXPR]; 4484276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned NumSubExprs; 4485276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation BuiltinLoc, RParenLoc; 4486276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp Op; 4487276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4488276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4489dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t, 4490dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicOp op, SourceLocation RP); 4491276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4492276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman /// \brief Build an empty AtomicExpr. 4493276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 4494276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4495276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getPtr() const { 4496276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[PTR]); 4497276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4498276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setPtr(Expr *E) { 4499276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[PTR] = E; 4500276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4501276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrder() const { 4502276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER]); 4503276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4504276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrder(Expr *E) { 4505276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER] = E; 4506276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4507276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal1() const { 45087a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (Op == Init) 45097a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return cast<Expr>(SubExprs[ORDER]); 4510276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4511276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL1]); 4512276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4513276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal1(Expr *E) { 45147a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall if (Op == Init) { 45157a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall SubExprs[ORDER] = E; 45167a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return; 45177a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall } 4518276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4519276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL1] = E; 4520276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4521276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrderFail() const { 4522276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4523276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER_FAIL]); 4524276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4525276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrderFail(Expr *E) { 4526276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4527276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER_FAIL] = E; 4528276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4529276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal2() const { 4530276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4531276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL2]); 4532276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4533276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal2(Expr *E) { 4534276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4535276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL2] = E; 4536276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4537276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4538276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp getOp() const { return Op; } 4539276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOp(AtomicOp op) { Op = op; } 4540276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned getNumSubExprs() { return NumSubExprs; } 4541276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setNumSubExprs(unsigned num) { NumSubExprs = num; } 4542276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4543dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 4544dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4545276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isVolatile() const { 4546276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getPtr()->getType()->getPointeeType().isVolatileQualified(); 4547276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4548276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4549276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isCmpXChg() const { 4550276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getOp() == AtomicExpr::CmpXchgStrong || 4551276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman getOp() == AtomicExpr::CmpXchgWeak; 4552276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4553276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4554276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4555276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 4556276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4557276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getRParenLoc() const { return RParenLoc; } 4558276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setRParenLoc(SourceLocation L) { RParenLoc = L; } 4559276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4560276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceRange getSourceRange() const { 4561276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return SourceRange(BuiltinLoc, RParenLoc); 4562276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4563276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const Stmt *T) { 4564276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return T->getStmtClass() == AtomicExprClass; 4565276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4566276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const AtomicExpr *) { return true; } 4567276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4568276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman // Iterators 4569276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman child_range children() { 4570276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return child_range(SubExprs, SubExprs+NumSubExprs); 4571276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4572276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}; 45735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 45745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 45755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4576