Expr.h revision 1c860d5640e8eebb11a5d515a761242b66761b0b
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 24f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 26525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 273b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 28b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 29403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 30c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 33590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 34c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 4056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 41409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 44f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 45833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 46d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 50f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 517ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 60f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 61bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool TD, bool VD, bool ContainsUnexpandedParameterPack) : Stmt(SC) { 628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 64f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 66bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 74f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 83905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 848320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 85f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setValueDependent(bool VD) { ExprBits.ValueDependent = VD; } 1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setTypeDependent(bool TD) { ExprBits.TypeDependent = TD; } 1160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return ExprBits.ContainsUnexpandedParameterPack; 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 135bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 136bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 138bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 14363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 145026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 146026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 147026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 148026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 149026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 150df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1527eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1537eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1547eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1557eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1567eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1577eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1597eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1607eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1617eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1627eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1637eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 1647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 1657eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 1667eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 1677eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 1687eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 1697eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 1707eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 174fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 17586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 176077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 1772514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 178e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 179e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1817eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 1827eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 18353202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 18944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 19044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 19144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 19244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 197fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 199ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2024f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2035daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 204ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 20586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2062514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 207e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 208077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 209e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 21144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 21244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2241c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 229077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2702c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2712c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 2722c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 2732c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 2742c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 2752c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 277369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 293369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 308f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3090943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3100943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3110943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3120943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 320f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 323f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 324f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 326f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 327f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 32856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 32956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 33056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 33156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 33256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 335f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 337f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 338f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 34433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 34533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 34633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34838d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 34938d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 35038d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 352f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 353f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 354f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 355f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 356093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 357093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 358c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 364c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 369590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 370590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 372590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3738070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 374590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 376c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 377c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3784204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 38194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3822d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 38394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 38694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 38794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 39094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 39194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 39294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 39394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 39494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 39594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 39694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 39794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 39894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 39994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 404e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 405e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 406e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 407e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 408e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 409e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 410e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 41194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 41294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4136ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 414019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 415019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 416019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4174ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4185b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 419cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 420cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 421cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 4224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 423cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 4246ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 42545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 427c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4286ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 429138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4306ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4316ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 43451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 43551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 4364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const; 43751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 438b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 439b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4411b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 442e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 4434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 444e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 44582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 44682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 44782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 44882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 44982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 45082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 45282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 45382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 45582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 45682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 45882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 45982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 46082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 461ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 462ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 463ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 464ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 465ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 467ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 468ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 469ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 470c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 471ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 472ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 473ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 474ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 47682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 47782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 47882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 47982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 48082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 48182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 482efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 48344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 485102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 48811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 48911ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 490369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 491369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 492369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 493369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 494369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 495369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 496369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 497369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 498369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 499369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 5004e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5024e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5034e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5042b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 50556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 50656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 50727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 50856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5102fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5112fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5122fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5132fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5144d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5154d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5164d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 517f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 518f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 519f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 520f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 521f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 522f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 523f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 524f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 5254d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 526ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 527ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 528ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 529ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 5326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 5336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 5356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 5366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 5376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 5386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 540558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 541558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 542558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 5432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 54475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 54575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 54675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 5472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 5484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 5494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 55056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 55156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 55256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 553ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 554ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 555ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 558898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 559898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 57256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 57356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 57456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 57556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 57656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 57756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 57856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 57956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 58056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 58156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 58256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 58356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 58456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 58556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 58656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->isDependentType(), T->isDependentType(), false), 58756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 58856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 58956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 59156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 59256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 59356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 59456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 59656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 59756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 59956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 60056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 60156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 60256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 60356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 60456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 60556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 60656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 60756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 60856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 60956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 61056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 61156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 61256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 61356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 61456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 61556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 61656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 61756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 61856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 61956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 62056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 62156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 62256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 62356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 62456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 62556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 62656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 62756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 62856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 629a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 630a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 631a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 63240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief The nested-name-specifier that qualifies the name, including 63340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// source-location information. 63440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 635a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 636a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 637a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 638a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 639a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 640a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 641a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 642c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 643a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 644a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 645c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 646a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 647a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 648a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 649a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 651a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 652833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 653833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 655c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 656a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 657833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 658833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 659a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 660d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 661d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 662bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeFrom(const TemplateArgumentListInfo &List, 663bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool &Dependent, bool &ContainsUnexpandedParameterPack); 664d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 6658dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 666d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 667a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 668c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 672a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 673c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 674a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 675a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 676c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 677a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 678a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 679a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 680c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 681c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // DecoratedD - The declaration that we are referencing, plus two bits to 682a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 683c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // (2) the declaration's name was followed by an explicit template 684a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 685dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 6862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 687a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6899e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 6902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// DNLoc - Provides source/type location info for the 6912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in DecoratedD. 6922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 6932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 6962cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 697a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 698c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 699a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 701c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 702a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 703a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 704a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 705a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 706096832c5ed5b9106fa177ebc148489760c3bc496John McCall 70740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 708dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 709d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 710f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 711663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 71240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 715f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 717663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 718663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 719663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 720c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7210da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7220da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7230da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7249e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 726f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, SourceLocation l) : 727bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(DeclRefExprClass, t, VK, OK_Ordinary, false, false, false), 728f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DecoratedD(d, 0), Loc(l) { 7290da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 7300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 732a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 73340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 734dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 735a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 736f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 738663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 7392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 74040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 7412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 7422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 743f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 7452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 746663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 747663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 748def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 749def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 750def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 751c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 752dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 753dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 754dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 755904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 7562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 7572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 7582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 7592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7609e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 7610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 76263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 766a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 767c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// \brief If the name was qualified, retrieves the nested-name-specifier 769a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 770a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 771a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 772a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 773c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 77440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getNameQualifier()->QualifierLoc.getNestedNameSpecifier(); 775a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 77640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 77740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the name was qualified, retrieves the nested-name-specifier 77840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 77940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 78040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 78140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 78240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 78340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getNameQualifier()->QualifierLoc; 78440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 78540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 786096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 787096832c5ed5b9106fa177ebc148489760c3bc496John McCall return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); 788096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 789096832c5ed5b9106fa177ebc148489760c3bc496John McCall 790096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 791096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 792096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 793096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 794096832c5ed5b9106fa177ebc148489760c3bc496John McCall 795096832c5ed5b9106fa177ebc148489760c3bc496John McCall if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 796096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 797096832c5ed5b9106fa177ebc148489760c3bc496John McCall 798096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 799096832c5ed5b9106fa177ebc148489760c3bc496John McCall getNameQualifier() + 1); 800096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 801096832c5ed5b9106fa177ebc148489760c3bc496John McCall 802096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 803096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 804096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 805096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 806a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 807d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 808096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 809096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 810096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 811096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 812096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 813096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 814096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 815096832c5ed5b9106fa177ebc148489760c3bc496John McCall 816d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 817d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 818d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 819096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 820096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 821d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 822c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 823a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 824a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 825a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 826096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 827a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 828c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 829096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 830a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 831c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 832a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 833a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 835096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 836a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 837c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 838096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 839a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 840c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 841a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 842a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 843a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 844096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 845a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 846c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 847096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 848a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 850a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 851a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 852a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 853096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 854a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 855c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 856096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 857a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 858c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 86099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 86563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 866663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 86760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 8683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 871d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 872d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 873227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 874227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 875227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 876227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 877848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 878848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 879848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 880848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 881227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 883227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 884227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 885227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 886227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 888f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 889bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 890bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 891f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 89517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 89617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 897227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 89817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 89917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 90017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 90117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 90217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 903848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 9043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 90563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 906227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 909227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 910d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 91363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 914227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 915227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 9179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 9189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 9199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 9209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 9219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 9229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 9239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 9249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 9259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 9269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 9279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 9289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 9299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 9309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 9329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 9349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 9359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 9379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 9389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 9409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 9419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 9429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 9439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 9449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 9459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 9479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 9509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 9519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 9529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 9539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 9569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 9579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 9589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 9599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 9609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 9649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 9669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 9689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 9699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 9709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 9749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 9759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 976bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 977bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 978f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 9809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 982a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 9839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 9849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // or UnsignedLongLongTy 9859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 9869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 9879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 9880b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 9899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 99063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 992313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 993313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 994313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 9959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 9960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 9970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 100463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 1010c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 1013c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 1014bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1015bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1016f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(value), Loc(l), IsWide(iswide) { 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 10200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 10210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1022018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1023c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 10300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 10310b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 10320b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 103777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 103877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 103963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1044720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1048720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1049bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1050bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 10519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 10529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 105517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 105817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 10599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 10619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 10639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 10659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 10679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 106817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1069720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 107017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1071c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1072da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1073da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1074da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1075da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 107817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 107917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 108063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 10861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 108863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10915d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 10925d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 10935d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 10945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 10955d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 10965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 10975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 10985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 10995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1100bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1101bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1102f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1104cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1106cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1107cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 11095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1110cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1111cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 111263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 11155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 11165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 111963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 11205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 11215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1122e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1123e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1124e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1125a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1126c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1127c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1128690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1129690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 11308bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1131690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1132c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1133c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1134c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1135c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1136c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1137c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 11393e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 11403e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 11443e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool IsPascal; 1145726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 1146726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 11472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1148f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false) {} 11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 11532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 11542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 11553e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson unsigned ByteLength, bool Wide, bool Pascal, 11563e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson QualType Ty, 1157a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 11582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 11592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 11613e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson unsigned ByteLength, bool Wide, 11623e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool Pascal, QualType Ty, SourceLocation Loc) { 11633e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson return Create(C, StrData, ByteLength, Wide, Pascal, Ty, &Loc, 1); 11642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1165a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1166673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1167673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1168673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1169b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1170b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1171b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 11722f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1174673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1175673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1176b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1177673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 11793e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 11803e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 11818d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1182b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1183b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1184b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 118533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 118633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 118733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1188726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1189726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1190726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1192726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1193726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1194726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1195726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1197673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1198673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1199673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 120008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 120108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 120208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 120308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 120408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 120508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 120608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 120708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 120808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 120908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 121008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1211673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1212b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1213b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1214b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 121663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 122563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 12325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1235898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1236f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1237bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1238bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1239898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1241c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1243c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1244c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 12455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1247c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1248c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 124963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1251313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1252313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1253c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1254313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1255313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1256313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1257c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1258313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 126563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 12700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1272dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1273dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1274dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1275dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1276dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1277dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1278dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12815baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 12825baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 12840799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12860799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1289f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1290f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1291f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1292de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1293bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1294bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 12950799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 12992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 13000b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13010799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 13020b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 13030b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 13050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 13060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 13090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 13100b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 13122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 13132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 13142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1316cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 13172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 13182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 13192085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13205a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 13210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 13220799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 13232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1324993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 13252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1327993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 13282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 13302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 13312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13320799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1338bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1339bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1340bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1341bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1342bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1343bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1344bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1345bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 134663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 135263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 136063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 13828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 13838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1384cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 13858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1386cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 13878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1388cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1389cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1390cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1391cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1392cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 13938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 13998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1403c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 14058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 14068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 14078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1408c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1409cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 14108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1411c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 14158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 14168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1417c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 14208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1423c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 14268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1429cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1430cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1431cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1432cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1435c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 14368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1438c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 14408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 14418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 14428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 14438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 14488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1449cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 14508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1451c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 14538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1456cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1457cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1458cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1460cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 14638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 146806dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 14698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 14768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1480c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1481c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1483c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 14848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 14858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1489c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 14908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1492c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1493c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1494c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1495c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 14968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 14978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 14988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1499c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 15008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 15018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 15038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 15048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 15058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 15078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 15088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1509c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 15118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 15128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 15158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const OffsetOfNode &getComponent(unsigned Idx) { 15188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 15208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 15258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1526c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 15288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 15298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 15328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 15338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 15348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 15358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 15388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 15408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 15418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 15448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 15458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 154763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 15498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 15528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 15538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 15568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 155863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 155963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 156063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 156163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 156263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 156363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 15648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 15658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1566f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1567f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1568f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1569f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1570f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 15710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1572d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1573a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1574d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1575d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 157742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1579f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1580f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1581f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1582f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1583ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 15842850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1585bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1586bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1587f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1588a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1589ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1590ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1591f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1592f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1593f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1594f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1595ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1596ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1597bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1598bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1599f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1600ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1601d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 16020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 16030b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1604f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1605f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 16060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1607f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1608f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1609f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1610f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 16110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 16130518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 16145ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 16155ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1616a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 16170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 16185ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 16190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1620caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 16210518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1622d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 16230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1624caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1625f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1626caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 16270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1629a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1630a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 16320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 16330b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 16350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 16360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 16370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 16380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 16390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 164076e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 16410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 16420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1645866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 164663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1647866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1648866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1651f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1653f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 165577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 165663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 166577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1670f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 167173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1672f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 16732850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1674bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1675bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1676bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 16772850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 167873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 167973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 168073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1682cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1683cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1684cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1685cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 16862324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 16872324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 16882324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 16892324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 16902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 169133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 169233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 169333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 169433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 16955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 16965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1697cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1698cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 16995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 17005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1701cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 17045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 170577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 17085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 17092324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 17125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17132324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 17165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 17181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 172077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 17215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1723026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1724cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1725cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 172663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 173463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 173563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 173663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1740b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 17411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1742b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1744b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1745b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 17465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1747cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 17485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1752b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1753cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1754cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1755cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1756cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1757cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1758cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1759cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1760cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1761cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1762cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1763cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1764cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1765cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1766cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1767cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1768cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1769cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1770cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1771cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1772cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 177342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1776f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17781f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1779ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 17801f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 17815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 17825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 178318b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1784a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1785d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1786d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1787d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1788d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1789d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1790a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1791a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1792bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1793bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1794bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1795a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 17965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 17975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 17991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1800aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1801cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1802cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1803cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1804aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 18055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 18065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 18075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1808cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 18115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1812cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 18135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1815934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1816934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1817934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1818cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1819934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1821d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1822d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1823d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 18248189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 18275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1829cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1830cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1831cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1832cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1833cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1834cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1835cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1836cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1837cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1838cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 18415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 18435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1844cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1845cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 18464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 18506dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 18516dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 18521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1853d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 18541f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1855866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 18562882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 18571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18594bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 18604bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 186388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 186477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 186563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 186663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 186763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 186863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1871ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 18746bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 18756bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1876161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 18776bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 18786bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1879ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1880ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 18815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1883ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1884ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1885f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1887ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 18912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 18922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 18932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1894ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 189583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 189783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 18986bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 18996bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1900c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 19016bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1903c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1904c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1905c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1906c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 19076bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1908c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 19091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 191083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 19116bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 19126bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 19136bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 191483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 191583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 191683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 19176bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1918c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1919c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1922f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1923f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 1924f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1925f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1926bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 1927bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 19282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 19292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 19302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 19312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 19322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 19332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 19342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 19352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 19362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 19372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 19382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1939f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 1940f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1941f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1942bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 1943bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 19442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 19452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 19466bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1947510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 19481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 194940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1950161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 19512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 1952d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1953f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 19541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 195588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 19565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 195757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 195857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 195957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 196057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 196157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1962f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1963f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 19641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 19656bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1966161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 19676bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1968161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1969161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 19706bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 19716bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 19726bb8017bb9e828d118e15e59d71c66bba323c364John McCall 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 19740979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 19750979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 19766bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 197983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 198083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 19826bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 198383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 198540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 198640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 198740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 198840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 198940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 199040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 199140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 199240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 199340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 199440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 199540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 199683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1997c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1998c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1999c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2000096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2002c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2004d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2005d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2006d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2007096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2008096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2009096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2010096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2011096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2012096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2013096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2014096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2015096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2016096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2017096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2018096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2019096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 2020096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2021096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2022096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2023096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2024096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2025096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2026096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2027096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2028096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2029096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2030096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2031096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2032096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2033096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 2034096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2035096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2036d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2037c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2039c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2041c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2042c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2044096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2045c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2047c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2048c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2049833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2050c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 20511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2053096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2054c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2056c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2057c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2059c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2062096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2063c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2066c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 20671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2068c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2069c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2071096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2072c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 20752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 20762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 20772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 20782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 20792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 20805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 20811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 20821f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2083ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2084ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2085026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 20861f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 20875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 208875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 208975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 209063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 20915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 209275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 209375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 209475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 209575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 209675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 20971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 209883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21021237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 210363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 21044045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 21054045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 21064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 21075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2110aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2111aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 21120fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 21130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 21140fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 21150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 21161d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 21171d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 21181d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 211942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 21205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2121e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2122aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 212342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2124f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2125f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2126bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2127bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2128bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 212942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2131ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2132ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2133ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2134ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 21355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 21365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2137ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2138e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2139e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2140ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2141ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 21420fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2143ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2144ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 214542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 214642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 214742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 214863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 21490fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 21500fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 21510fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 21520fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 215373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 21540fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 215573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2156aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2159aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2160aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21621237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 216363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2164aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2165aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 216649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 216749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 216849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 216949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 21700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2171cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 21725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2174cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 21750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2176409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2177daa8e4e888758d55a7a759dd4a91b83921cef222John McCall void CheckCastConsistency() const { 2178409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2179409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 21805cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2181cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2182cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2183409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2184409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2185f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2186f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2187409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2188409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2189409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2190409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2191409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2192409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2193409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2194409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2195404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 2196409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2197409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2198409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2199409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2200409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2201409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2202409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2203409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2204409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2205409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2206409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2207569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 22082bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 2209f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 22102bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 2211f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 22122bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 2213f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 22142bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 2215f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 2216daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 2217daa8e4e888758d55a7a759dd4a91b83921cef222John McCall // fallthrough to check for null base path 2218daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 2219daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 22200ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 2221f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 2222daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_NoOp: 2223daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 2224daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 2225daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 2226daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_MemberPointerToBoolean: 2227daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingComplexToBoolean: 2228daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralComplexToBoolean: 22295082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_LValueBitCast: // -> bool& 22305082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_UserDefinedConversion: // operator bool() 2231f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2232409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2233409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2234409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2235409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2236409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 22420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2244f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2245f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2246898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2247898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2248898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2249898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2250898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2251bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2252bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2253bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 22548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2255daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 22568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 22578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 2258daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 2259f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 22601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2261087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2262f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 22638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 22648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 22658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 22688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 22698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2270f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2271f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 22720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 22730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2274087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2275087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 22766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 22776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 22786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 22796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 22806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 22816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 22826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 228341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2284f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2285f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 22868e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 22878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2288f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2289f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2290f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2292f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2293f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 229441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22964bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 22974bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 22980835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 22990835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 230263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 23030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 23040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 230549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 230649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 230749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 230849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 230949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2310bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2311bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2312906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2313bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2314bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2315bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2316bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2317906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 23181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2319906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2320906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2321906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2322906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2323bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2324bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 23250835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2326906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2327f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 23285baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 23305baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 233190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2332087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2334f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2335f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2336f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2337f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2338f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 23395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2340f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 23415baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2342f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2343f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2344f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2345f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 23465baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2347f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2348f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2349087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 235063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23510835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 23520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 235390045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 235649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 235749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 235849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 235949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 236049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 236249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 236349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 236449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 236549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 236649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 236749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 23685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 236949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 237049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 237149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 237249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 237349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2374906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2375906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 23760835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 23779d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 23789d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 23799d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 238049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 238149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2382f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2383f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2384f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2385f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 238649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2387db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2388f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2389f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2390db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 239149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 23929d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 23939d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 23949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 23959d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 23969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 239749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 239849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 23999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 240049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24024bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 24034bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 240449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 240549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 240649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 240749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24086eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 240949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 241049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 24116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2412b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2413b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2414f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2415f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 241741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2418f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 241941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 242049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2421db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2422f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2423f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2424f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2425f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2426f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2428f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2429f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2430f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2431f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2432f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2433db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2434b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2435db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2436db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2437b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2438db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2439db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 244063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2441b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 24455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24466eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 24475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 24503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 24513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 24523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 24533fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 24543fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 24553fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 24563fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 24573fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 24583fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 24593fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 24603fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 24613fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 24623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 24633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 24643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 24653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 24663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 24675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 24685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 24705baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 247117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 24720799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 24730799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 24740799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 247517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 24765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 247917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2480f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 248117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2482f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2483898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2485bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2486bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2487898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 24881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 24901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 24915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 24925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2494db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 24962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2497db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 249817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2499db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2500db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25010799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2502db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2503db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2505db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 25065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2507db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2508db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 250963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 25105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 25115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 25145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 25155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 25165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25170799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2518a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2519063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2520063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2521063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2522063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2523063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2524063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2525063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2526063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 25275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2528200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 25292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 25302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 25310799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 25322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 25330799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2534aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 25352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 25360799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2537f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 25390799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2540f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 25420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 25431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 25450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2546aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 25472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 25480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2549f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25500e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 25510e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 25520e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25530e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 25540e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 25550e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 25562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 25572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 25580e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 25590e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 25600e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25610e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 25620e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 25632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 25642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 25650e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 25660e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 25670e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 25704bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 25714bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 25725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 25741237c673c07f9d827129ba02720108816abde562Ted Kremenek 25751237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 257663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 257763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 257863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 25791237c673c07f9d827129ba02720108816abde562Ted Kremenek 25805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 258117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2582f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 25832333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2584f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 25852333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2586bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2587bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2588bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 25892333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 25901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 25911237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 25925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2593ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 25941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 25952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 25965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 25995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 26005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 26015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 26025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 26035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 26045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2605ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2606ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 26075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2608f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2609f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2610f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 261117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2612f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2613ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2614ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 26165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 26175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2619ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2620ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2621ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2622ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2623ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2624ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2625ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2626ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2627ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2628ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2629ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2630ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2631ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 26325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 26331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 26355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 263856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 263956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 264056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 264156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 264256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 264356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 264456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 264556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 264656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 264756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool TD, bool VD, 264856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 264956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 265056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 265156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, T, VK, OK, TD, VD, ContainsUnexpandedParameterPack), 265256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 265356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 265456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 265556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 265656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 265756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 265856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 265956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 266056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 266156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 266256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 266356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 266456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 266556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 266656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 266756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 266856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 266956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 267056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 267156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 267256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 267356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 267456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 267556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 267656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 267756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 267856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 267956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 268056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 268156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 268256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 268356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 26841237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 26855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 268656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 268756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 26885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 268947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 269056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 26910943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 269256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2693898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2694898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2695898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 269656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 269756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 269856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2699bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 270056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 270156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 270256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 27031237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 27041237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27051237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27061237c673c07f9d827129ba02720108816abde562Ted Kremenek } 27075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2708ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2709ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 271056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2711ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2712395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 271356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 27145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2715395a2abf0028968d85958610e393e067885dc14fTed Kremenek 271656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 271756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 271856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 272056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 272156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 272256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 27235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2724f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 272556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 27265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 272747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 272863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 27295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 27305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 27335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27361237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 273763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 273863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 273963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 27405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 274256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 274356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 274456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 274556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 274656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 274756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 274856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 274956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 275156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 275256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 275356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 275456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 275556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 275656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 275756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 275956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 276056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 276156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 276256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 276356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 276456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 276556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 276656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 276756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 276856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 276956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 277056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 277156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 277256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 277356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 277456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 277556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 277756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 277856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 278056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 278156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 278256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 278356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 278456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 278556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 278656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 278856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 278956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 279056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 279256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 279356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 279456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 279656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 279756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 279856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 279956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 280056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 280156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 280356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 280456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 280556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 280656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 280756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 280856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 281056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 281156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 281256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 281356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 281456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 281556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 281656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 281856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 281956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 282056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 282156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 282256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 282456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 282556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 282656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 282856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 283056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 283156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 283256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 283356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 283456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 283556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 283656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 283756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 283856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 283956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 284056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 28416481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 28426481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 28435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2844ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 28455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2846ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 28476481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2848bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false), 28492333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 28501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 28521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 28537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 28547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 28557d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 28567d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 28577d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 28587d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 28597d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 286063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 28615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 28625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2864ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 2865ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 28667d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 28675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 28681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 28695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28706481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 28711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28721237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 287363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 28745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2875ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2876ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2877ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2878ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2879f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 2880f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 2881f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 2882ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 28835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2884ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2885ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 28862333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2887d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2888d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2889f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 2890bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor T->isDependentType(), false, false), 28912333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28936a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 28946a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 28956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 28965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 28975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 28986a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 28996a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 290063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2901ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2902ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2904026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 29056a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2906026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 29076a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 29081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2909ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 29101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2911ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2912ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 29131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29141237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 291563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 2916ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2917ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2918d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2919d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2920d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2921d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2922d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2923d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2924d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2925d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2926d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2927d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2928d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2929d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2930d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2931d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 29325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2933d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2934d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2935d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 2936a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 29371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 2938bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 293994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 294094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 294294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 294394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 294494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 294594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 294794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 294894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 294994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 295063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2951d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2952d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2953d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2955d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2956d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 29571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2958d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2959d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2960d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2961d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 29621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2963aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 2964aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 2965aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2966d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2967d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2968d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 29695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2970d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2971d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2972d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 29735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2974d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 29751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2976888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 297794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2978dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2979dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 29809a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2981d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2983d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 298463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 298563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 298663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2987d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2988d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2989d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 29901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2991d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 29927976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 29937976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 29947976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 29957976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 29967976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 29977976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2998d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 29991237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 30005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3001d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3002d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3003f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3004f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3005ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3006bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3007bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3008bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3009bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 30101237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 30111237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 30121237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 30131237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 30141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 30157976932a1c256d447316ffac58e9821417725e34Eli Friedman 301644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 301744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 301844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 30197976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 30207976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 30214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 30227976932a1c256d447316ffac58e9821417725e34Eli Friedman 30237976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 30247976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 30254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 30267976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 30277976932a1c256d447316ffac58e9821417725e34Eli Friedman } 30287976932a1c256d447316ffac58e9821417725e34Eli Friedman 30295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 303044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 30315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 303244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 30335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 303444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 303544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 303644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 303744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 304044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 30411237c673c07f9d827129ba02720108816abde562Ted Kremenek 304263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3043d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3044d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3045d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 30461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3047d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3048d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 30491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30501237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 305163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 305263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 305363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3054d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3055d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 30562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 30572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 30582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 30592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 30602d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 30612d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 30622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 30632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 30642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 30652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 30662d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 30671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3068bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false), 3069f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 30702d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 307144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 307244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 307344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 30742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 30752d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 307644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 30772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 307863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30792d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 30802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 30812d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 30821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 30832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 30842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 30851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 308763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 30882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 30892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 309074626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 30917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 30925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 30932cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 30947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 30957c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 30962cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 30972cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3098f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3099bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3100bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3101bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 31022cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 31037c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 31047c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 31051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3107d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3108d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 31095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 31105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3111d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3112d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 31132cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 31142cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 31152cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3116d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3117d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3119d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3120d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3121d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 312263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 31241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31257c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 31267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 31277c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 31287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 31291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31307c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 313163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 31327c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 31354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 31364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 31374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 31384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 31394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 31404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 31414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 31424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3143196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 31454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 31464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 31474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 31484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 31494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 31504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 31514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3152196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 31544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 31554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 31564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 31574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 31584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 31594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 31603498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 31614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 31624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 31634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3164196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 31664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 31674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 31684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 31694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 31704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 317166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3172ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3173709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3174709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 317566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 31784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 31794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 31804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 31810bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 31820bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 31830bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 31840bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3185a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3186a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3187a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3188a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 318966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3190709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3191709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3192ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3193d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3194d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3195709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3196709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3198ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 31991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3200aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3201aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3202aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 320316c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3204c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 320666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 32071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 320816c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3209c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 321166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 32121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3214c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32159e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 32169e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3217c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3218fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3219709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 32201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 32224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 32244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 32254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 32264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 32274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 32284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 32294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 32304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 32314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 32324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 32344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3235fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3236709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3237c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 32380bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 32390bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 32400bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 32410bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 32420bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 32430bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 32440bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 32450bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 32460bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3247c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3248c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3249b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3250b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3251b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 32521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3253d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3254d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3255d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 325687fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 325787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 32584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 32594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 32604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 32624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 32634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 32644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3265a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 32661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3267d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3268a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3269a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 327063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3271c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 327266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 32731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 327466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 327566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 32761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 327766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 327863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 327963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 328063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 328163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 32821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3283709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 32848111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3285709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 32868111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3288ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 32898111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3290ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 32918111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3292ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 32938111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3294ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 32958111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 329666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 329766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 329805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 329905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 330005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 330105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 330205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 330305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 330405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 330605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 330705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 330805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 330905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 331005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 331105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 331205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 331305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 331405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 331505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 331605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 331705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 331805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3319ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3320ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3321ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3322ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3323ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 332405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 332505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 332605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 332705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3328eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 332905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3330eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 333105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 333205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 333305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 333405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3335ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3336ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3337ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3338ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 333905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 334005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 334105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 334205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 334305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3344ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3345319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3346ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3347eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 33489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 33499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 335005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3351d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3352d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3353d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3354d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 335505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 335605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 335705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 335805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 335905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 336005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 336105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 336205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 336305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 336405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 33651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 336605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 336705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 33681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 336905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 337005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 337105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 337205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 337305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 337405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 337505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 337605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 337705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 337805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 337905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 338005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 338105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 338205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 338305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 33841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 338505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 338605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 338705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 338805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 338905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 339005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 339105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 339205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 339305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 339405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 339505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 339605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 339705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 339805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 339905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 340005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 340105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 340205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 340305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 340405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 340505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 340605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 340705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 340805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 340905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3410ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3411ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 341205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 34131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 34141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 341505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 341605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 341705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 341805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 341905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 342005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 342105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 342305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 342405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 342505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 342605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 342705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 342805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 342905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 343005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 343105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 34321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 343305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 343405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 343505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 343605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 343705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 343805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 343905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 344005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 344105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 344205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 344305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 344405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 344505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 344605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 344705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 344805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 344905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 345005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 345105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 345205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 345305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 345405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 345505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 345605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 345705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 345805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 345905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 346087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 346187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 346287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 346387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 346487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 346505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 346605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 346705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 346805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 346905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 347005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 347105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 347205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 347305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 347405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 347505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 347605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 347705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 347805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 347905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 348005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 348105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 348205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 348305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 348405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 348505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 348605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 34874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3488d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3489d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3490d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3491d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3492d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3493d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 34944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 34954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 34964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 34974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 34984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 34994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 350024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 350124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 350224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 350324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 350424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 350524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 350605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 350705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 350905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 351005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 351105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3512eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 351305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3514d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3515d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 351605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 351705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 351805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 351905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 352005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 3521ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 35221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 35231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3524ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 352505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3526cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3527cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3528cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3529cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3530cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3531cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3532cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3533cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3534cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3535711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3536711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3537c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3538319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3539d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 354005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 354105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 354205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 354305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 354405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 354505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 354605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3547d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 354805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 354905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3550eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3551eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3552d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 355305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 355405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 355605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 355705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 355805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 355905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 356005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 356105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3563d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3564d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3565d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3566d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3567d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3568d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3569d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3570d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3571d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3572d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3573d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3574d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3575d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3576d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3577d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3578d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3579d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3580d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3581d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3582d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3583ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3584ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3585319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3586ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3587ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 358824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 358924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 359063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 359105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 35931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 359405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 359505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 359605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 359863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 359963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 360063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 360163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 36023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 36033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 36043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 36053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 36063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 36071a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 36081a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 36093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 36101a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 36111a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 36121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 36133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 36141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3615f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3616bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, false, false) { } 36173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3618d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3619d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3620d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3621d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 36221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 36233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 36243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 36253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 36263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 362763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 36283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 36293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 36303498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 36313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 363263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 36372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 36382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 36392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 36402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 36421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 36432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 36442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 364637bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 36471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 36491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 36512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 36522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 36532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 36562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 36572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 36582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 366083ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 36611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 36632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 36642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 366563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 36662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 36671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 36682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 36691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 36702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 36721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 367463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 367563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 367663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 367737bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 367860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 36793397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 36802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 36812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3683f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// \brief Represents a C1X generic selection. 3684f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3685f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling 3686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3687f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3688f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3689f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3690f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3691f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3692f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3693f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3694f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3695f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3696f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3697f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3698f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3699f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3700f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3701f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3702f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3703f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3704f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3705f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3706f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3707f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3708f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3709f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3710f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3711f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3712f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3713f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3714f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3715f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3716f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3717f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3718f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3719f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3720f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3721f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3722f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3723f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 3724f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3725f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 3726f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3727f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3728f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3729f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3730f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3731f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 3732f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3733f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 3734f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 3735f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3736f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 3737f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3738f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 3739f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 3740f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 3741f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3742f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 3743f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 3744f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3745f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 3746f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3747f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 3748f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 3749f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3750f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 3751f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3752f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 3753f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 3754f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 3755f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 3756f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 3757f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3758f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3759f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 3760f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 3761f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3762f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 3763f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3764f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 3765f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 3766f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3767f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 3768f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 3769f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3770f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 3771f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 3772f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 3773f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3774f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3775f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 3776f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3777f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 3778f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 3779f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3780f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 3781f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 3782f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3783f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 3784f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 3785f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3786f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 3787f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3788f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 3789f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 3790f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3791f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3792f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 3793f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 3794f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 37954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 37964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 37974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 37984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3799a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3800a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3801a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3802a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3803a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 380473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 380573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 380673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3807a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3808a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3809d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3810a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3811a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3812f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 3813f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 38140943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 38150943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 3816bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 3817bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 3818d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 38191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3820d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3821d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3822d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3823d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3824a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3825a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3826d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3827d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3828d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3829d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3830d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3831d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3832d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3833d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3834a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3835a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 38361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3837a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3838a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3839a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 38401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3841a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3842a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3843a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 38441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 384563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3846a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3847a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 38481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38492140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 38502140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 38512140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 38521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 38541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3855a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3856a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 38571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3858a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 385963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 3860a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3861a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3862a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 386356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 38649c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 38654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 386656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 386756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 38684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3869469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 3870f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 3871bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType(), false, false), 3872469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 38739c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 387484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 387584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 387684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3877d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 387856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 387984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 388084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 388156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 388256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 388356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 388456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 38859c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 388663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 388756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 38889c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 38899c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 389056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 389156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 389256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 38931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 38949c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 38954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 38964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 38971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 389963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 39004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 39011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39026b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 39036b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 39044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 39056b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 39064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 39077d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 39087d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 39094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 39106b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 39116b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 391294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 391394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 391494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 391594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 391694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 39171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39186b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 39196b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 39206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 392194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 392294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 392394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 392494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 392563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 39261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 392894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39307d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 39317d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 393289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 39331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 39341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 39354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 39364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 39371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 393963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 39404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 39414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 39425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 39435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 39445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3945