Expr.h revision 75e85048e73fcde2ce9d8a48dfdb1220e132eb59
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" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 25525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 263b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 27b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 28403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 29c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 32590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 33c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 378e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 40409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 43f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 44833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 45d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 487ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 49f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 507ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 60bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool TD, bool VD, bool ContainsUnexpandedParameterPack) : Stmt(SC) { 618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 63f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 64f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 65bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 73f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 82905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 838320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 84f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 958e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setValueDependent(bool VD) { ExprBits.ValueDependent = VD; } 990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1148e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setTypeDependent(bool TD) { ExprBits.TypeDependent = TD; } 1150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 116d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return ExprBits.ContainsUnexpandedParameterPack; 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 134bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 135bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 136bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 138bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 14263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 145026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 146026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 147026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 148026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 149df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1517eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1527eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1537eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1547eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1557eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1567eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1587eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1597eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1607eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1617eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1627eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 1637eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 1647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 1657eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 1667eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 1677eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 1687eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 1697eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 173fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 17486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1752514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 176e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 177e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1797eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 1807eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 18153202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 18744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 18844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 18944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 19044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 195fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 197ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2004f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2015daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 202ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 20386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2042514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 205e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 206e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 20844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 20944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2652c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2662c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 2672c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 2682c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 2692c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 2702c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 272369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 288369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 301f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 302f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 303f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3040943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3050943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3060943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3070943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 308f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 309f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 310f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 311f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 320f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 32356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 32456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 32556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 32656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 32756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 328f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 331f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 332f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 33933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 34033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 34133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 34438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 34538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 347f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 348f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 349f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 350f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 351093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 352093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 353c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3542b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3562b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3572b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 364590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 365590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 367590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3688070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 369590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 371c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 372c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3734204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 37694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3772d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 37894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 38194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 38294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 38594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 38694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 38794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 38894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 38994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 39094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 39194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 39294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 39394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 39494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 397e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 398e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 399e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 400e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 401e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 404e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 405e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 40694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 40794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4086ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 409019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 410019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 411019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4135b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 414cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 415cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 416cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 4174ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 418cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 4196ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 42045b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 422c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4236ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 424138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4256ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4266ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 428c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 42951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 43051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 4314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const; 43251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 433b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 434b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4361b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 437e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 4384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 439e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 44082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 44182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 44282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 44382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 44482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 44582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 44682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 44782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 44882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 44982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 45082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 45182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 45382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 45482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 45582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 456ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 457ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 458ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 459ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 460ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 462ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 463ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 464ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 465c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 466ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 467ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 468ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 469ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 470c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 47182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 47282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 47382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 47482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 47582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 47682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 477efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 47844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 480102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 48311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 48411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 485369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 486369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 487369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 488369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 489369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 490369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 491369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 492369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 493369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 494369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 4954e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 4961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 4974e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 4984e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 4992b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 50056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 50156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 50227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 50356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5052fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5062fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5072fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5082fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5094d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5104d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5114d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 512f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 513f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 514f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 515f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 516f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 517f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 518f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 519f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 5204d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 521ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 522ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 523ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 524ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 5276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 5286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 529c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 5306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 5316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 5326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 5336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 535558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 536558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 537558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 5382f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 53975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 54075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 54175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 5422b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 5434e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 5444e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 54556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 54656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 54756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 548ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 549ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 550ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 5511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 553898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 554898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 5571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 56756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 56856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 56956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 57056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 57156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 57256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 57356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 57456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 57556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 57656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 57756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 57856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 57956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 58056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 58156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->isDependentType(), T->isDependentType(), false), 58256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 58356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 58456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 58556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 58656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 58756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 58856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 58956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 59156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 59256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 59456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 59556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 59756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 59856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 59956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 60056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 60156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 60256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 60356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 60456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 60556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 60656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 60756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 60856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 60956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 61056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 61156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 61256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 61356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 61456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 61556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 61656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 61756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 61856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 61956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 62056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 62156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 62256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 62356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 626a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 62740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief The nested-name-specifier that qualifies the name, including 62840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// source-location information. 62940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 630a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 631a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 632a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 633a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 634a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 635a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 636a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 637c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 638a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 639a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 640c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 641a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 642a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 643a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 644a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 645c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 646a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 647833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 648833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 649a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 651a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 652833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 653833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 655d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 656d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 657bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeFrom(const TemplateArgumentListInfo &List, 658bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool &Dependent, bool &ContainsUnexpandedParameterPack); 659d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 6608dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 661d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 662a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 663c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 667a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 668c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 669a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 670a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 671c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 672a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 673a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 674a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 675c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 676c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // DecoratedD - The declaration that we are referencing, plus two bits to 677a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 678c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // (2) the declaration's name was followed by an explicit template 679a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 680dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 6812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 682a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6849e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 6852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// DNLoc - Provides source/type location info for the 6862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in DecoratedD. 6872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 6882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 690a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 6912cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 693c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 696c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 697a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 699a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 701096832c5ed5b9106fa177ebc148489760c3bc496John McCall 70240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 703dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 704d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 705f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 706663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 70740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 710f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 712663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 713663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 714663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 715c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7160da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7170da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7180da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7199e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 721f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, SourceLocation l) : 722bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(DeclRefExprClass, t, VK, OK_Ordinary, false, false, false), 723f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DecoratedD(d, 0), Loc(l) { 7240da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 7250da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 727a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 72840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 729dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 730a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 731f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 733663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 7342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 73540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 7362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 7372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 738f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 7402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 741663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 742663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 743def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 744def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 745def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 746c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 747dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 748dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 749dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 750904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 7512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 7522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 7532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 7542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7559e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 7560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 75763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 759a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 760a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 761a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 762c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 763c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// \brief If the name was qualified, retrieves the nested-name-specifier 764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 766a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 767a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 76940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getNameQualifier()->QualifierLoc.getNestedNameSpecifier(); 770a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 77140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 77240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the name was qualified, retrieves the nested-name-specifier 77340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 77440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 77540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 77640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 77740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 77840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getNameQualifier()->QualifierLoc; 77940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 78040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 781096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 782096832c5ed5b9106fa177ebc148489760c3bc496John McCall return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); 783096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 784096832c5ed5b9106fa177ebc148489760c3bc496John McCall 785096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 786096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 787096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 788096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 789096832c5ed5b9106fa177ebc148489760c3bc496John McCall 790096832c5ed5b9106fa177ebc148489760c3bc496John McCall if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 791096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 792096832c5ed5b9106fa177ebc148489760c3bc496John McCall 793096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 794096832c5ed5b9106fa177ebc148489760c3bc496John McCall getNameQualifier() + 1); 795096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 796096832c5ed5b9106fa177ebc148489760c3bc496John McCall 797096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 798096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 799096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 800096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 801a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 802d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 803096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 804096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 805096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 806096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 807096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 808096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 809096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 810096832c5ed5b9106fa177ebc148489760c3bc496John McCall 811d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 812d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 813d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 814096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 815096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 816d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 818a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 819a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 820a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 821096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 822a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 823c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 824096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 825a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 826c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 827a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 828a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 829833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 830096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 831a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 833096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 834a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 835c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 836a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 837a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 838a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 839096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 840a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 841c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 842096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 843a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 845a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 846a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 847a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 848096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 849a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 850c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 851096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 852a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 853c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 85599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 86063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 861663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 86260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 8633397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 866d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 867d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 868227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 869227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 870227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 871227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 872848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 873848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 874848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 875848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 876227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 878227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 879227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 880227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 881227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 883f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 884bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 885bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 886f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 89017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 89117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 892227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 89317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 89417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 89517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 89617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 89717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 898848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 8993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 90063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 901227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 904227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 905d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 90863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 909227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 910227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 9129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 9139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 9149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 9159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 9169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 9179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 9189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 9199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 9209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 9219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 9229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 9239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 9249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 9259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 9279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 9299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 9309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 9329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 9339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 9359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 9369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 9379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 9389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 9399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 9409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 9429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 9459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 9469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 9479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 9489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 9519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 9529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 9539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 9549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 9559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 9599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 9619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 9639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 9649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 9659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 9699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 9709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 971bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 972bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 973f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 9759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 977a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 9789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 9799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // or UnsignedLongLongTy 9809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 9819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 9829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 9830b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 9849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 98563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 987313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 988313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 989313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 9909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 9910b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 9920b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 99963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 1005c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 1008c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 1009bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1010bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1011f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(value), Loc(l), IsWide(iswide) { 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 10150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 10160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1017018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1018c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 10250b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 10260b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 10270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 103277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 103377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 103463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1039720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1043720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1044bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1045bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 10469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 10479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 105017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 10529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 105317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 10549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 10569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 10589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 10609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 106317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1064720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 106517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1066c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1067da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1068da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1069da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1070da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 107317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 107417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 107563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 108363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10865d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 10875d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 10885d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 10895d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 10905d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 10915d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 10925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 10935d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 10945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1095bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1096bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1097f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1099cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 11001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1101cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1102cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 11045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1105cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1106cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 110763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 11105d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 11115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11135d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 111463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 11155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 11165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1117e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1118e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1119e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1120a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1121c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1122c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1123690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1124690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 11258bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1126690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1127c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1128c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1129c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1130c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1131c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1132c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 1137726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 1138726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 11392085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1140f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false) {} 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11442085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 11452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 11462085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 11472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 1148a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 11492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 11502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 11522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 11532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 11542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 11552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1156a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1157673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1158673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1159673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1160b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1161b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1162b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 11632f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1165673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1166673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1167b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1168673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 1170673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 1171673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 11728d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1173b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1174b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1175b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 117633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 117733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 117833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1179726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1180726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1181726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1183726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1184726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1185726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1186726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1188673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1189673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1190673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 119108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 119208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 119308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 119408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 119508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 119608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 119708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 119808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 119908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 120008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 120108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1202673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1203b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1204b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1205b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 120763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 121577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 121663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 12235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1226898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1227f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1228bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1229bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1230898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1232c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1234c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1235c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 12365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1238c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1239c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 124063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1242313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1243313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1244c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1245313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1246313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1247313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1248c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1249313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 125663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 12610518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1263dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1264dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1265dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1266dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1267dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1268dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1269dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 12735baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 12750799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12770799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1280f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1281f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1282f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1283de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1284bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1285bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 12860799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12880b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 12902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 12910b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 12920799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 12930b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 12940b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 12955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 12960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 12970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 13000b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 13010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 13032085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 13042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 13052085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1307cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 13082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 13092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 13102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13115a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 13120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 13130799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 13142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1315993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 13162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1318993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 13192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 13212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 13222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13230799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1329bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1330bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1331bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1332bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1333bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1334bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1335bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1336bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 133763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 134363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 135163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 13568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 13578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 13628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1375cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1377cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1379cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1380cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1381cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1382cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1383cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 13848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 13858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 13878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 13908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 13938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 13978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1400cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1402c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1405c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 14068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 14078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1408c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 14118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 14168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 14178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1418c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1420cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1421cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1422cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1423cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1424c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1426c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 14278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 14318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 14328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 14338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 14358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 14388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1440cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 14418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1442c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1447cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1448cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1449cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1450c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1451cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1452c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 14558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 14568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1457c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 14588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 14598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange getRange() const { return Range; } 14608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 14618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1463c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 14668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 14688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 14698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1474c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 14768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1480c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 14818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1483c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1484c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1486c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 14878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 14898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1490c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 14918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 14928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 14948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 14958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 14968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 14988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 14998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1500c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 15038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 15058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1507c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const OffsetOfNode &getComponent(unsigned Idx) { 15098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 15118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 15168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1517c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 15198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 15208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 15248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 15258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 15268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 15298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 15318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 15328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1533c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 15358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 15368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 153863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 15408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 15438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 15448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 15478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 154963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 155063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 155163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 155263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 155363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 155463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 15558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 15568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 15580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 15590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 15600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 15610518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1562d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1563a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1564d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1565d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 156742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1569a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 15700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 15710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 1572f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary, 1573ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 15742850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1575bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1576bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1577ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1578a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1579ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1580ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1582ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1583ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1584f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary, 1585ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1586ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1587bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1588bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1589ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1590ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1591d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 15920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 15930b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 15940b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 15950b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 15960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 15980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 15990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16000518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 16010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 16025ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 16035ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1604a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 16050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 16065ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 16070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1608caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 16090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1610d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 16110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1612caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1613caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1614caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 16150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1617a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1618a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 16200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 16210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 16230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 16240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 16250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 16260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 16270518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 162876e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 16290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 16300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1633866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 163463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1635866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1636866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 16375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 16405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 164377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 164463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 165377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 16565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16572324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1658f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 165973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1660f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 16612850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1662bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1663bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 16652850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 166673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 166773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 166873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1670cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1671cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1672cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1673cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 16742324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 16752324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 16762324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 16772324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 16782324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 167933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 168033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 168133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 168233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 16835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 16845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1685cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1686cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 16875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 16885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1689cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 16925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 169377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 16965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 16972324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 16981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 17005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 17045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 170877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1711026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1712cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1713cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 171463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 172177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 172263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 172363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 172463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1728b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1730b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1732b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1733b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 17345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1735cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 17365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 17391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1740b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1741cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1742cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1743cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1744cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1745cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1746cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1747cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1748cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1749cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1750cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1751cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1752cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1753cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1754cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1755cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1756cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1757cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1758cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1759cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1760cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 176142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 17625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1764f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17661f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1767ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 17681f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 17695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 17705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 177118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1772a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1773d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1774d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1775d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1776d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1777d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1778a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1779a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1780bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1781bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1782bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1783a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 17845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1788aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1789cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1790cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1791cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1792aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 17945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 17955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1796cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 17975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 17995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1800cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1803934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1804934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1805934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1806cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1807934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1809d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1810d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1811d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 18128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 18131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 18155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1817cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1818cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1819cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1820cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1821cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1822cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1823cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1824cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1825cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1826cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 18305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 18315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1832cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1833cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 18344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 18371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 18386dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 18396dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1841d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 18421f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1843866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 18442882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18474bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 18484bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 185188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 185277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 185363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 185463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 185563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 185663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1859ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 18626bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 18636bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1864161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 18656bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 18666bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1867ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1868ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 18695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 18701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1871ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1872ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1873f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1875ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 18792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 18802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 18812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1882ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 188383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 188583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 18866bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 18876bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1888c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 18896bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1891c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1892c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1893c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1894c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 18956bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1896c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 18971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 189883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 18996bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 19006bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 19016bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 190283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 190383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 190483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 19056bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1906c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1907c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1910f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1911f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 1912f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1913f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1914bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 1915bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 19162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 19172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 19182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 19192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 19202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 19212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 19222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 19232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 19242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 19252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 19262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1927f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 1928f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1929f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1930bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 1931bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 19322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 19332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 19346bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1935510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 193740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1938161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 19392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 1940d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1941f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 19421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 194388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 19445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 194557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 194657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 194757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 194857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 194957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1950f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1951f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 19521f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 19536bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1954161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 19556bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1956161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1957161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 19586bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 19596bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 19606bb8017bb9e828d118e15e59d71c66bba323c364John McCall 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 19620979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 19630979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 19646bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 196783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 196883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 19706bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 197183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 197440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 197540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 197640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 197740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 197840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 197940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 198040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 198140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 198240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 198340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 198483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1985c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1986c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1987c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1988096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 19891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1990c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1992d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1993d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1994d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1995096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1996096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1997096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1998096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1999096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2000096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2001096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2002096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2003096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2004096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2005096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2006096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2007096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 2008096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2009096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2010096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2011096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2012096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2013096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2014096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2015096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2016096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2017096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2018096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2019096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2020096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2021096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 2022096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2023096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2024d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2025c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2027c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 20281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2029c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2030c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2032096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2033c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2035c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2036c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2037833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2038c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2041096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2042c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2044c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2045c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2047c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2050096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2051c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2054c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2056c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2057c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2059096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2060c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 20632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 20642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 20652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 20662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 20672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 20685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 20691f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 20701f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2071ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2072ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2073026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 20741f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 207675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 207775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 207863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 20795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 208075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 208175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 208275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 208375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 208475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 20851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 208683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 20875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 20891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20901237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 209163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 20924045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 20934045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 20944045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 20955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2098aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2099aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 21000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 21010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 21020fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 21030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 21041d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 21051d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 21061d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 210742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 21085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2109e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2110aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 211142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2112f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2113f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2114bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2115bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2116bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 211742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2119ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2120ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2121ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2122ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 21235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 21245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2125ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2126e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2127e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2128ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2129ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 21300fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2131ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2132ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 213342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 213442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 213542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 213663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 21370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 21380fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 21390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 21400fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 214173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 21420fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 214373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2144aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 21451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2147aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2148aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 21491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21501237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 215163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2152aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2153aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 215449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 215549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 215649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 215749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 21580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2159cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 21605baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2162cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 21630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2164409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2165daa8e4e888758d55a7a759dd4a91b83921cef222John McCall void CheckCastConsistency() const { 2166409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2167409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 21685cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2169cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2170cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2171409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2172409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2173f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2174f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2175409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2176409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2177409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2178409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2179409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2180409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2181409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2182409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2183404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 2184409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2185409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2186409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2187409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2188409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2189409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2190409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2191409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2192409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2193409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2194409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2195569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 21962bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 2197f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 21982bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 2199f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 22002bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 2201f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 22022bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 2203f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 2204daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 2205daa8e4e888758d55a7a759dd4a91b83921cef222John McCall // fallthrough to check for null base path 2206daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 2207daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 22080ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 2209f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 2210daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_NoOp: 2211daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 2212daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 2213daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 2214daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_MemberPointerToBoolean: 2215daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingComplexToBoolean: 2216daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralComplexToBoolean: 22175082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_LValueBitCast: // -> bool& 22185082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_UserDefinedConversion: // operator bool() 2219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2220409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2221409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2222409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2223409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2224409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2226f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2227f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2228f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2229f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 22300835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2231f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2233f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2234898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2235898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2236898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2237898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2238898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2239bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2240bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2241bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 22428e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2243daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 22448e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 22458e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 2246daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 2247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2249087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 22518e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 22528e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 22538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 22568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 22578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2258f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2259f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 22600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 22610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2262087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2263087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 22646eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 22656eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 22666eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 22676eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 22686eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 22696eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 22706eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 227141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2272f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2273f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 22748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 22758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2276f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2277f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2278f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2279f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2280f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2281f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 228241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22844bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 22854bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 22860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 22870835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 229063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 22910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 22920835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 229349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 229449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 229549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 229649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 229749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2298bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2299bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2300906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2301bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2302bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2303bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2304bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2305906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2307906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2308906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2309906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2310906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2311bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2312bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 23130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2314906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2315f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 23165baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 23185baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 231990045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2320087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2321f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2322f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2323f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2324f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2325f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2326f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 23275baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2328f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 23295baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2330f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2331f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2332f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 23345baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2335f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2336f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2337087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 233863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 23400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 234190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 234449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 234549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 234649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 234749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 234849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 23491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 235049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 235149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 235249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 235349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 235449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 235549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 235749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 235849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 235949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 236049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 236149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2362906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2363906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 23640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 23659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 23669d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 23679d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 236849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 236949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 237449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2375db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2376f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2377f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2378db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 237949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 23809d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 23819d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 23829d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 23839d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 23849d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 238549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 238649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 23879d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 238849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23904bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 23914bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 239249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 239349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 239449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 239549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 23966eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 239749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 239849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 23996eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2400b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2401b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2402f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2403f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2404f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 240541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 240741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 240849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2409db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2410f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2411f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2412f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2413f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2414f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2415f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2417f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2418f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2419f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2420f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2421db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2422b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2423db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2424db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2425b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2426db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2427db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 242863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2429b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24346eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 24355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 24383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 24393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 24403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 24413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 24423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 24433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 24443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 24453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 24463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 24473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 24483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 24493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 24503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 24513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 24523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 24533fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 24543fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24575baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 24585baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 245917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 24600799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 24610799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 24620799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 246317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 24645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 24651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 246717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 246917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2470f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2472bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2474bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 24761237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24771237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 24795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 24805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2482db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 24842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2485db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 248617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2487db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2488db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 24890799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2490db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2491db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 24925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2493db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 24945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2495db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2496db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 249763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 25025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 25035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 25045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25050799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2506a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2507063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2508063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2509063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2510063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2511063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2512063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2513063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2514063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 25155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2516200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 25172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 25182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 25190799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 25202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 25210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2522aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 25232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 25240799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2525f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 25270799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2528f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 25300799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 25330799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2534aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 25352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 25360799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2537f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 25380e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 25390e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 25400e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25410e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 25420e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 25430e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 25442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 25452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 25460e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 25470e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 25480e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25490e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 25500e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 25512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 25522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 25530e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 25540e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 25550e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 25584bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 25594bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 25605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 25621237c673c07f9d827129ba02720108816abde562Ted Kremenek 25631237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 256463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 256563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 256663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 25671237c673c07f9d827129ba02720108816abde562Ted Kremenek 25685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 256917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2570f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 25712333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2572f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 25732333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2574bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2575bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2576bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 25772333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 25781237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 25791237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 25805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2581ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 25832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 25845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 25875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 25885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 25895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 25905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 25915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 25925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2593ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2594ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 25955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2596f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2597f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2598f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 259917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2600f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2601ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2602ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 26031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 26045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 26055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2607ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2608ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2609ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2610ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2611ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2612ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2613ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2614ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2615ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2616ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2617ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2618ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2619ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 26205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 26235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 262656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 262756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 262856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 262956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 263056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 263156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 263256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 263356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 263456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 263556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool TD, bool VD, 263656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 263756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 263856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 263956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, T, VK, OK, TD, VD, ContainsUnexpandedParameterPack), 264056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 264156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 264256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 264356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 264456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 264556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 264656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 264756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 264856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 264956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 265056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 265156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 265256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 265356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 265456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 265556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 265656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 265756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 265856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 265956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 266056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 266156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 266256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 266356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 266456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 266556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 266656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 266756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 266856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 266956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 267056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 267156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 26721237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 26735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 267456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 267556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 26765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 267747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 267856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 26790943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 268056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2681898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2682898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2683898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 268456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 268556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 268656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2687bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 268856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 268956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 269056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 26911237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 26921237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26931237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26941237c673c07f9d827129ba02720108816abde562Ted Kremenek } 26955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2696ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2697ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 269856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2699ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2700395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 270156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 27025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2703395a2abf0028968d85958610e393e067885dc14fTed Kremenek 270456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 270556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 270656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 27071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 270956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 271056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 27115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2712f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 271356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 27145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 271547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 271663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 27175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 27215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 27231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27241237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 272563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 272663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 272763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 27285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 273056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 273156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 273256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 273356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 273456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 273556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 273656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 273756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 273856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 273956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 274056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 274156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 274256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 274356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 274456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 274556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 274656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 274756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 274856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 274956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 275056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 275156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 275256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 275356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 275456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 275556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 275656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 275756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 275856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 275956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 276056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 276156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 276256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 276356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 276456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 276556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 276656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 276756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 276856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 276956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 277056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 277256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 277356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 277456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 277556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 277756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 277856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 278056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 278156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 278256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 278356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 278456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 278556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 278656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 278856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 278956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 279156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 279256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 279356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 279456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 279556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 279656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 279856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 279956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 280056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 280156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 280256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 280356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 280456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 280656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 280756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 280856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 280956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 281056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 281256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 281356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 281456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 281556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 281656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 281856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 281956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 282056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 282156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 282256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 282456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 282556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 282656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 282856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 28296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 28306481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 28315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2832ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 28335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2834ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 28356481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2836bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false), 28372333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 28381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 28401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 28417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 28427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 28437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 28447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 28457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 28467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 28477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 284863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 28495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 28505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2852ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 2853ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 28547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 28555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 28561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 28575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28586481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 28591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28601237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 286163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 28625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2863ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2864ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2865ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2866ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2867f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 2868f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 2869f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 2870ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 28715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2872ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2873ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 28742333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2875d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2876d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2877f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 2878bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor T->isDependentType(), false, false), 28792333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 28801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28816a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 28826a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 28836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 28845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 28855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 28866a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 28876a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 288863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2889ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2890ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 28911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2892026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 28936a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2894026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 28956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 28961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2897ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 28981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2899ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2900ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 29011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29021237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 290363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 2904ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2905ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2906d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2907d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2908d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2909d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2910d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2911d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2912d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2913d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2914d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2915d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2916d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2917d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2918d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2919d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 29205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2921d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2922d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2923d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 2924a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 29251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 2926bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 292794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 292894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 29291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 293094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 293194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 293294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 293394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 29341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 293594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 293694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 293794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 293863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2939d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2940d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2941d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 29421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2943d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2944d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 29451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2946d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2947d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2948d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2949d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2951aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 2952aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 2953aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2954d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2955d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2956d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 29575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2958d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2959d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2960d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 29615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2962d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 29631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2964888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 296594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2966dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2967dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 29689a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2969d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 29701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2971d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 297263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 297363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 297463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2975d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2976d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2977d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 29781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2979d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 29807976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 29817976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 29827976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 29837976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 29847976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 29857976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2986d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 29871237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 29885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2989d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2990d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2991f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 2992f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 2993ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2994bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 2995bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 2996bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 2997bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 29981237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 29991237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 30001237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 30011237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 30021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 30037976932a1c256d447316ffac58e9821417725e34Eli Friedman 300444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 300544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 300644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 30077976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 30087976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 30094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 30107976932a1c256d447316ffac58e9821417725e34Eli Friedman 30117976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 30127976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 30134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 30147976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 30157976932a1c256d447316ffac58e9821417725e34Eli Friedman } 30167976932a1c256d447316ffac58e9821417725e34Eli Friedman 30175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 301844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 30195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 302044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 30215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 302244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 302344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 302444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 302544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 302744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 302844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 30291237c673c07f9d827129ba02720108816abde562Ted Kremenek 303063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3031d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3032d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3033d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 30341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3035d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3036d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 30371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30381237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 303963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 304063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 304163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3042d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3043d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 30442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 30452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 30462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 30472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 30482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 30492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 30502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 30512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 30522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 30532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 30542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 30551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3056bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false), 3057f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 30582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 305944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 306044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 306144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 30622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 30632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 306444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 30652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 306663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30672d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 30682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 30692d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 30701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 30712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 30722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 30731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 307563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 30762d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 30772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 307874626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 30797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 30805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 30812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 30827c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 30837c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 30842cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 30852cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3086f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3087bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3088bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3089bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 30902cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 30917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 30927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 30931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 309474626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3095d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3096d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 30975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 30985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3099d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3100d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 31012cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 31022cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 31032cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3104d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3105d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3107d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3108d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3109d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 311063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31117c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 31121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31137c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 31147c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 31157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 31167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 31171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 311963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 31207c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 31234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 31244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 31254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 31264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 31274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 31284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 31294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 31304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3131196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 31334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 31344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 31354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 31364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 31374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 31384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 31394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3140196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 31424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 31434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 31444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 31454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 31464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 31474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 31483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 31494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 31504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 31514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3152196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 31534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 31544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 31554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 31564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 31574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 31584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 315966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3160ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3161709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3162709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 316366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 31641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 31664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 31674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 31684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 31690bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 31700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 31710bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 31720bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3173a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3174a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3175a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3176a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 317766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3178709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3179709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3180ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3181d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3182d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3183709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3184709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 31851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3186ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 31871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3188aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3189aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3190aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 319116c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3192c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 31934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 319466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 31951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319616c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3197c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 31984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 319966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3202c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32039e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 32049e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3205c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3206fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3207709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 32081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 32104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 32124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 32134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 32144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 32154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 32164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 32174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 32184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 32194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 32204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 32224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 32234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 3224709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3225c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 32260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 32270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 32280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 32290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 32300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 32310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 32320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 32330bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 32340bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3235c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3236c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3237b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3238b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3239b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3241d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3242d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3243d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 324487fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 324587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 32464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 32474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 32484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 32504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 32514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 32524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3253a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 32541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3255d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3256a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3257a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 325863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3259c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 326066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 32611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 326266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 326366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 32641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 326566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 326663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 326763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 326863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 326963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 32701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3271709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 32728111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3273709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 32748111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 32751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3276ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 32778111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3278ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 32798111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3280ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 32818111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3282ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 32838111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 328466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 328566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 328605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 328705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 328805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 328905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 329005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 329105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 329205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 32931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 329405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 329505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 329605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 329705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 329805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 329905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 330005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 330105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 330205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 330305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 330405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 330505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 330605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3307ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3308ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3309ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3310ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3311ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 331205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 331305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 331405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 331505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3316eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 331705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3318eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 331905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 332005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 332105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 332205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3323ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3324ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3325ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3326ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 332705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 332805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 332905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 333005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 333105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3332ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3333319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3334ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3335eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 33369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 33379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 333805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3339d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3340d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3341d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3342d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 334305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 334405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 334505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 334605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 334705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 334805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 334905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 335005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 335105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 335205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 33531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 335405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 335505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 33561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 335705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 335805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 335905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 336005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 336105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 336205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 336305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 336405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 336505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 336605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 336705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 336805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 336905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 337005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 337105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 33721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 337305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 337405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 337505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 337605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 337705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 337805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 337905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 338005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 338105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 338205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 338305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 338405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 338505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 338605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 338705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 338805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 338905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 339005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 339105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 339205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 339305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 339405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 339505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 339605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 339705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3398ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3399ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 340005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 34021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 340305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 340405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 340505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 340605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 340705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 340805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 340905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 34101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 341105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 341205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 341305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 341405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 341505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 341605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 341705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 341805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 341905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 34201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 342105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 342205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 342305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 342405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 342505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 342605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 342705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 342805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 342905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 343005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 343105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 343205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 343305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 343405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 343505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 343605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 343705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 343805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 343905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 344005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 344105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 344205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 344305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 344405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 344505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 344605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 344705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 344887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 344987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 345087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 345187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 345287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 345305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 345405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 345505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 345605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 345705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 345805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 345905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 346005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 346105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 346205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 346305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 346405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 346505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 346605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 346705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 346805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 346905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 347005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 347105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 347205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 347305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 347405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 34754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3476d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3477d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3478d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3479d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3480d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3481d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 34824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 34834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 34844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 34854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 34864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 34874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 348805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 348905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 34901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 349105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 349205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 349305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3494eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 349505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3496d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3497d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 349805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 349905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 350005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 350105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 350205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 3503ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 35041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 35051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3506ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 350705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3508cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3509cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3510cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3511cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3512cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3513cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3514cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3515cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3516cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3517711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3518711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3520319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3521d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 352205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 352305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 352405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 352505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 352605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 352705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 352805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3529d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 353005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 353105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3532eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3533eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3534d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 353505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 353605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 35371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 353805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 353905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 354005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 354105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 354205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 354305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 354405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3545d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3546d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3547d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3548d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3549d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3550d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3551d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3552d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3553d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3554d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3555d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3556d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3557d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3558d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3559d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3560d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3561d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3562d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3563d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3564d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3565ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3566ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3567319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3568ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3569ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 357063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 35731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 357863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 357963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 358063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 358163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 35823498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 35833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 35843498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 35853498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 35863498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 35871a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 35881a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 35893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 35901a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 35911a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 35921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 35933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 35941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3595f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3596bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, false, false) { } 35973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3598d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3599d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3600d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3601d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 36021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 36033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 36043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 36053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 36063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 360763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 36083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 36093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 36103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 36113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 361263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 361305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 361405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 36172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 36182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 36192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 36202ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36212ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 36221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 36232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 36242ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36252ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 362637bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 36271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 36291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 36312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 36322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 36332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 36362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 36372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 36382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 364083ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 36411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 36432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 36442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 364563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 36462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 36471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 36482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 36491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 36502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 36512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 36521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 365463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 365563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 365663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 365737bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 365860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 36593397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 36602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 36612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 36621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 36644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 36654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 36664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3667a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3668a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3669a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3670a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3671a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 367273525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 367373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 367473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3675a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3676a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3677d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3678a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3679a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3680f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 3681f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 36820943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 36830943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 3684bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 3685bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 3686d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 36871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3688d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3689d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3690d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3691d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3692a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3693a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3694d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3695d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3696d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3697d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3698d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3699d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3700d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3701d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3702a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3703a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 37041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3705a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3706a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3707a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 37081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3709a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3710a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3711a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 37121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 371363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3714a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3715a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 37161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37172140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 37182140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 37192140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 37201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 37221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3723a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3724a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 37251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3726a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 372763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 3728a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3729a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3730a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 373156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 37329c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 37334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 373456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 373556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 37364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3737469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 3738f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 3739bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType(), false, false), 3740469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 37419c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 374284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 374384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 374484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3745d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 374656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 374784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 374884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 374956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 375056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 375156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 375256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 37539c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 375463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 375556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 37569c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 37579c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 375856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 375956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 376056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 37611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 37629c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 37634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 37644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 37651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 376763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 37684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 37691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37706b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 37716b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 37724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 37736b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 37744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 37757d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 37767d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 37774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 37786b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 37796b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 378094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 378194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 378294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 378394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 378494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 37851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37866b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 37876b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 37886b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 378994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 379094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 379194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 379294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 379363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 37941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 379694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 37971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37987d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 37997d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 380089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 38011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 38034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 38044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 380763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 38084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 38094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 38105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 38115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3813