Expr.h revision 65aa6885818d4b4eea2e5a9d12085b2398148662
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 24f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 26525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 273b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 28b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 29403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 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, 175077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 1762514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 177e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 178e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1807eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 1817eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 18253202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 18844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 18944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 19044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 19144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 196fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 198ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2014f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2025daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 203ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 20486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2052514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 206e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 207077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 208e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 21044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 21144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2231c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 228077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2692c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2702c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 2712c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 2722c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 2732c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 2742c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 276369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 292369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 304f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3080943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3090943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3100943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3110943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 320f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 323f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 324f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 326f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 32756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 32856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 32956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 33056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 33156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 332f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 335f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 337f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 34333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 34433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 34533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 34838d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 34938d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 351f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 352f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 353f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 354f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 355093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 356093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 357c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 368590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 369590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 371590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3728070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 373590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 375c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 376c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3774204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 38094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3812d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 38294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 38594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 38694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 38994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 39094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 39194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 39294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 39394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 39494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 39594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 39694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 39794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 39894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 401e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 404e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 405e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 406e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 407e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 408e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 409e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 41094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 41194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4126ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 413019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 414019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 415019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4164ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4175b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 418cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 419cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 420cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 4214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 422cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 4236ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 42445b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 426c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4276ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 428138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4296ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4306ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 43351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 43451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 4354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const; 43651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 437b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 438b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4401b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 441e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 4424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 443e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 44482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 44582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 44682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 44782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 44882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 44982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 45182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 45282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 45482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 45582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 45682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 45782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 45882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 45982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 460ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 461ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 462ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 463ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 464ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 465c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 466ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 467ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 468ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 470ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 471ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 472ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 473ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 474c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 47582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 47682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 47782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 47882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 47982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 48082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 481efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 48244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 484102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 48711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 48811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 489864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 490864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 491864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 492864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 493864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 494369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 495369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 496369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 497369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 498369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 499369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 500369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 501369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 502369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 503369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 5044e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5064e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5074e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 50956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 51056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 51127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 51256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5142fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5152fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5162fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5172fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5182f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 5192f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 5202f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 5212f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5222f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 5232f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 5242f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 5252f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5264d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5274d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5284d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 529f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 530f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 531f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 532f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 533f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 534f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 535f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 536f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 5374d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 538ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 539ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 540ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 541ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 5421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 5446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 5456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 546c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 5476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 5486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 5496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 5506eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 552558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 553558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 554558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 5552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 55675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 55775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 55875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 5592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 5604e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 5614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 56256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 56356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 56456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 565ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 566ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 567ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 569898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 571898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 58456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 58556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 58656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 58756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 58856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 58956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 59056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 59156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 59256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 59356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 59456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 59556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 59656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 59756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 59856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->isDependentType(), T->isDependentType(), false), 59956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 60056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 60156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 60256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 60356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 60456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 60556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 60656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 60756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 60856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 60956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 61056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 61156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 61256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 61356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 61456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 61556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 61656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 61756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 61856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 61956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 62056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 62156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 62256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 62356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 62456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 62556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 62656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 62756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 62856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 62956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 63056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 63156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 63256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 63356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 63456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 63556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 63656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 63756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 63856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 63956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 64056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 641a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 642a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 643a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 644a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 645a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 646c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 647a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 648a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 649c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 650a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 651a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 652a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 653a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 654c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 655a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 656833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 657833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 658a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 659c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 660a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 661833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 662833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 663a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 664d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 665d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeFrom(const TemplateArgumentListInfo &List, 667bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool &Dependent, bool &ContainsUnexpandedParameterPack); 668d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 6698dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 670d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 671a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 672cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 673cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 674cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 675cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 676cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 677cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 678cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 679cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 680cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 681cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 682cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 683cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 684cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 685cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 6863aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 6873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 6883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 6893aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 690cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasExplicitTemplateArgs: 691cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 692cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// C++ template argument list. 6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 694cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 695cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 6962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 697cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6999e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 700cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 701cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7046857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7056857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7067e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7076857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 708a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 709cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7106857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7116857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7126857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 713a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 714096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7183aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7203aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7213aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7223aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7233aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7303aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 7313aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 7323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7347e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7363aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 7372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 738f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 740663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 741663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 742663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 7437e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7479e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 749cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L) 750cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), 751cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(L) { 752cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 753cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = 0; 7543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 7550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 7560da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 758a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 75940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 760dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 761a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 762f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 7640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 765663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 7662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 76740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 7682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 7692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 770f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 7722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 7732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 774663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 775663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 7763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 7773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 778def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 779def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 7807e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 781cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 782cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 783cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 784904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 7852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 7862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 7872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 7882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7899e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 7900b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 79163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 793a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 794a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 795cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 7967e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7977e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 798a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 799a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 800a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 801a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8027e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8036857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 804a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 80540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8067e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 80740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 80840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 80940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 81040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8117e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8126857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 81340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 81440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8183aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8203aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8213aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8223aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8233aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 8263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 8273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8307e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief Determines whether this declaration reference was followed by an 8317e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// explict template argument list. 832096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 833cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth return DeclRefExprBits.HasExplicitTemplateArgs; 834096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8357e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 836096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 837096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 838096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 839096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 8403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 8413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>( 8423aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 8433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8443aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 8453aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>( 8463aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 8477e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8483aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 849096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8507e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 851096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 852096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 853096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 854096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 855a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 856d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 857096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 858096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 859096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 860096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 861096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 862096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 863096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8647e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 865d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 866d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 867d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 868096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 869096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 870d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 8717e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 872a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 873a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 874a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 875096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 876a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 8777e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 878096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 879a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 8807e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 881a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 882a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 884096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 885a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8867e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 887096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 888a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 8897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 890a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 891a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 892a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 893096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 894a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8957e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 896096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 897a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 8987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 899a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 900a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 901a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 902096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 903a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9047e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 905096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 906a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9077e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 90999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 91463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 9157e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 91660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 9173397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 920d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 921d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 922227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 923227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 924227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 925227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 926848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 927848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 928848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 929848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 930227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 932227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 933227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 934227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 935227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 937f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 938bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 939bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 940f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 94217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 94417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 94517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 946227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 94717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 94817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 94917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 95017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 95117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 952848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 9533a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 95463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 955227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 958227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 959d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 96263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 963227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 964227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 9669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 9679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 9689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 9699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 9709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 9719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 9729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 9739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 9749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 9759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 9769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 9779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 9789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 9799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 9819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 9839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 9849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 9869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 9879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 9899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 9909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 9919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 9929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 9939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 9949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 9969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 9979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 9999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 10019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 10029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 10059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 10079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 10099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 10139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 10179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 10189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 10199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 10239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 10249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1025bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1026bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1027f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 10291dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 10301dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 10319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1033a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 10341dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 10351dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 10361dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 10371dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 10399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 10401dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 10419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 10420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 104463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1046313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1047313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1048313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 10499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 10500b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 10510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 105863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 1064c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 1067c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 1068bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1069bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1070f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(value), Loc(l), IsWide(iswide) { 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 10740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 10750b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1076018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1077c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10830b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 10840b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 10850b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 10860b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 109177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 109277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 109363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 10979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1098720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1102720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1103bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1104bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 11059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 11069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 110917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 11119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 111217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 11139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 11149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 11159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 11169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 11179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 11199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 11219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 112217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1123720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 112417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1125c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1126da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1127da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1128da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1129da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 113217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 113317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 113463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 114263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 11465d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 11475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 11485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 11495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 11505d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 11515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 11525d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 11535d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1156f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1158cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 11591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1160cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1161cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 11635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1164cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1165cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 116663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 11695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 11705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 117363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 11745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 11755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1176e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1177e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1178e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1179a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1180c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1181c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1182690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1183690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 11848bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1185690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1186c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1187c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1188c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1189c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1190c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1191c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 11933e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 11943e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 11983e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool IsPascal; 1199726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 1200726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 12012085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1202f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1203bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false) {} 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12062085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 12072085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 120865aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide, 120965aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1210a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 12112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 12122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 121365aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide, 12143e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool Pascal, QualType Ty, SourceLocation Loc) { 121565aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad return Create(C, Str, Wide, Pascal, Ty, &Loc, 1); 12162085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1217a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1218673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1219673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1220673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1221b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1222b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1223b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 12242f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1226673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1227673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1228b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1229673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 12313e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 12323e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 12338d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1234b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1235b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1236b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 123733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 123833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 123933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1240726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1241726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1242726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1244726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1245726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1246726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1247726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1249673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1250673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1251673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 125208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 125308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 125408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 125508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 125608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 125708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 125808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 125908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 126008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 126108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 126208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1263673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1264b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1265b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1266b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 126863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 127763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 12845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1289bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1290bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1291898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1293c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1295c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1296c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 12975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1299c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1300c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 130163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1303313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1304313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1305c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1306313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1307313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1308313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1309c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1310313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 131763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13210518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 13220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1324dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1325dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1326dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1327dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1328dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1329dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1330dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 13345baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 13360799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 13380799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1344de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1345bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1346bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 13470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 13512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 13520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13530799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 13540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 13550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 13570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 13580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 13610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 13620b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 13642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 13652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 13662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1368cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 13692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 13702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 13712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 13725a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 13730799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 13740799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 13752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1376993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 13772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1379993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 13802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 13822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 13832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 13840799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1390bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1391bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1392bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1393bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1394bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1395bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1396bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1397bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 139863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 140463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 141263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 14168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 14178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 14188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 14198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1420c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 14218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 14238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 14248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 14308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 14318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 14328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 14338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 14358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1436cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1438cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1440cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1441cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1442cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1443cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1444cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 14468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 14488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1449c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 14518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1452c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 14568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 14578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 14588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 14598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1460c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1461cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 14628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1463c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 14688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 14728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1473c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1479c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 14808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1481cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1482cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1483cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1484cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1487c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 14898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1490c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 14928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 14938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 14948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 14958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 14968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 14998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 15008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1501cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1503c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 15058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1507c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1508cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1509cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1510cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1512cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1513c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 15158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 15168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 15178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 15198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 152006dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 15228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 15268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 15278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 15288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 15298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 15308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 15318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1532c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1533c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 15348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1535c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 15368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 15378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 15388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 15408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1541c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 15428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1544c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1545c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1546c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1547c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 15498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 15508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 15528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 15538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 15558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 15568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 15578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 15598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 15608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1561c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 15638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 15648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 15668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 15678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15698cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 15708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15718cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 15728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 15758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 15778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1578c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 15808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 15818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 15848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 15858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 15868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 15878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15888cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 15898cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 15908cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 15918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 15938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 15948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 15958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 15968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 15998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 16008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 160263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 16038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 16048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 16078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 16088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 16118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 161363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 161463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 161563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 161663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 161763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 161863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 16198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 16208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1621f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1622f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1623f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1624f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1625f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 16260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1627d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1628a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1629d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1630d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 163242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 16335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1634f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1635f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1636f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1637f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1638ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 16392850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1640bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1641bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1642f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1643a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1644ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1645ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1646f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1647f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1648f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1649f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1650ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1651ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1652bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1653bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1654f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1655ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1656d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 16570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 16580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1659f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1660f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 16610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1662f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1663f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1664f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1665f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 16660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 16680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 16695ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 16705ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1671a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 16720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 16735ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 16740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1675caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 16760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1677d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 16780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1679caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1680f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1681caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 16820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16830b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1684a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1685a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 16870b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 16880b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 16900518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 16910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 16920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 16930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 16940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 169576e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 16960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 16970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1700866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 170163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1702866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1703866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1706f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1708f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 171163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 17195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 172077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 17225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 17235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17242324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1725f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 172673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1727f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 17282850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1729bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1730bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1731bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 17322850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 173373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 173473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 173573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1737cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1738cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1739cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1740cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 17412324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 17422324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 17432324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 17442324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 17452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 174633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 174733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 174833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 174933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 17505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 17515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1752cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1753cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 17545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 17555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1756cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 17571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 17595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 176077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 17635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 17642324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 17675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17682324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 17691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 177077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 17715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 177463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 177577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 17765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1778026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1779cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1780cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 178163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 17825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 178963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 179063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 179163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1795b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 17961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1797b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1799b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1800b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1802cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 18035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 18045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 18055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1807b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1808cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1809cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1810cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1811cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1812cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1813cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1814cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1815cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1816cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1817cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1818cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1819cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1820cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1821cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1822cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1823cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1824cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1825cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1826cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1827cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 182842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1831f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18331f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1834ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 18351f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 18365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 18375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 183818b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1839a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1840d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1841d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1842d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1843d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1844d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1845a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1846a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1847bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1848bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1849bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1850a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 18515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 18525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 18535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1855aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1856cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1857cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1858cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1859aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1863cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1867cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1870934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1871934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1872934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1873cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1874934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1876d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1877d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1878d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 18798189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 18825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1884cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1885cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1886cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1887cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1888cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1889cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1890cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1891cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1892cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1893cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 18965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1899cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1900cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 19014ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 19041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 19056dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 19066dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1908d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 19091f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1910866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 19112882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19144bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 19154bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 191888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 191977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 192063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 192163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 192263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 192363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1926ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 19275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 19296bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 19306857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 19316857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 19326857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 19336857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 19346857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 19356857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 19366857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 1937161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 19386bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 19396bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1940ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1941ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 19425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1944ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1945ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1946f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1948ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 19522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 19532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 19542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1955ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 195683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 195883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 19596bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 19606bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1961c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 19626bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1964c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1965c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1966c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1967c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 19686bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1969c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 19726bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 19736bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 19746bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 197583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 197683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 197783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 19786bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1979c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1980c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1983f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1984f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 1985f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1986f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1987bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 1988bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 19892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 19902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 19912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 19922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 19932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 19942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 19952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 19962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 19972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 19982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 19992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2000f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2001f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2002f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2003bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2004bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 20062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 20076bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 2008510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 201040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2011161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 20122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2013d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2014f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 20151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 20175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 201857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 201957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 202057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 202157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 202257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2023f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2024f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 20251f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 20266bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2027161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 20286bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2029161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2030161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 20316bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 20326bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 20336bb8017bb9e828d118e15e59d71c66bba323c364John McCall 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 20350979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 20360979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 20376bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 204083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 204183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 20436bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 204483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 204740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 204840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 204940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 205040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 205140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 205240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 205340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 205440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 205540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 205640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 205783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2058c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2059c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 2060c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2061096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2063c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2065d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2066d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2067d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2068096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2069096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2070096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2071096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2072096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2073096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2074096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2075096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2076096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2077096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2078096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2079096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2080096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 2081096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2082096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2083096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2084096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2085096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2086096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2087096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2088096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2089096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2090096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2091096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2092096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2093096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2094096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 2095096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2096096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2097d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2098c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2100c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2102c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2103c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2105096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2106c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2108c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2109c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2110833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2111c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2114096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2115c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2117c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2118c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2120c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2123096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2124c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2127c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 21281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2129c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2130c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2132096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2133c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 21362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 21372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 21382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 21392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 21402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 21421f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 21431f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2144ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2145ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2146026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 21471f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 21485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 214975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 215075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 215163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 21525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 215375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 215475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 215575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 215675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 215775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 215983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 21605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21631237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 216463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 21654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 21664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 21674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 21685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2171aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2172aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 21730fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 21740fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 21750fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 21760fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 21771d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 21781d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 21791d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 218042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 21815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2182e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2183aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 218442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2185f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2186f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2187bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2188bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2189bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 219042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2192ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2193ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2194ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2195ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 21965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 21975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2198ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2199e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2200e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2201ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2202ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 22030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2204ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2205ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 220642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 220742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 220842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 220963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 22100fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 22110fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 22120fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 22130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 221473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 22150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 221673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2217aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2220aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2221aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 22221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22231237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 222463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2225aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2226aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 222749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 222849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 222949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 223049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 22310835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2232cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 22335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2235cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 22360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2237409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2238daa8e4e888758d55a7a759dd4a91b83921cef222John McCall void CheckCastConsistency() const { 2239409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2240409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 22415cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2242cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2243cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2244409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2245409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2247f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2248409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2249409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2250409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2251409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2252409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2253409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2254409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2255409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2256404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 2257409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2258409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2259409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2260409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2261409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2262409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2263409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2264409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2265409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2266409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2267409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2268569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 22692bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 2270f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 22712bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 2272f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 22732bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 2274f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 22752bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 2276f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 2277f85e193739c953358c865005855253af4f68a497John McCall case CK_ObjCProduceObject: 2278f85e193739c953358c865005855253af4f68a497John McCall case CK_ObjCConsumeObject: 2279daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 2280daa8e4e888758d55a7a759dd4a91b83921cef222John McCall // fallthrough to check for null base path 2281daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 2282daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 22830ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 2284f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 2285daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_NoOp: 2286daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 2287daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 2288daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 2289daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_MemberPointerToBoolean: 2290daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingComplexToBoolean: 2291daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralComplexToBoolean: 22925082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_LValueBitCast: // -> bool& 22935082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_UserDefinedConversion: // operator bool() 2294f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2295409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2296409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2297409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2298409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2299409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2300f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2301f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2302f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2303f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2304f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2305654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2306654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2307654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2308654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2309654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2310654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 23110835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2319898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2320bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2321bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2322bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 23238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2324daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 23258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2326654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 2327daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 2328f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2330087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2331f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 23328e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2333654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 23348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 23351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 23378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 23388e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2339f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2340f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 23410835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 23420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2343087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2344087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 23456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 23466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 23476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 23486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 23496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 23506eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 23516eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 235241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2353f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2354f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 23558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 23568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2357f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2358f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2359f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2360f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2361f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2362f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 236341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23654bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 23664bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 23670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 23680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 237163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 23720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 23730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 237449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 237549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 237649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 237749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 237849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2379bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2380bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2381906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2382bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2383bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2384bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2385bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2386906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 23871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2388906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2389906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2390906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2391906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2392bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2393bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 23940835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2395906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2396f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 23975baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2398f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 23995baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 240090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2401087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2402f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2403f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2404f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2405f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2406f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2407f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 24085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 24105baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2411f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2412f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2413f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2414f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 24155baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2417f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2418087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 241963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24200835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 24210835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 242290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 242549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 242649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 242749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 242849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 242949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 243149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 243249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 243349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 243449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 243549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 243649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 24375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 243849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 243949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 244049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 244149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 244249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2443906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2444906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 24450835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 24469d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 24479d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 24489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 244949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 245049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2451f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2452f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2453f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2454f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 245549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2456db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2457f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2458f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2459db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 246049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 24619d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 24629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 24639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 24649d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 24659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 246649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 246749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 24689d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 246949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24714bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 24724bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 247349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 247449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 247549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 247649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24776eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 247849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 247949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 24806eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2481b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2482b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2483f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2484f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2485f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 248641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2487f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 248841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 248949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2490db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2491f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2492f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2493f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2494f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2495f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2496f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2497f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2498f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2499f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2500f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2501f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2502db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2503b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2504db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2505db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2506b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2507db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2508db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 250963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2510b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 25115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 25145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25156eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 25165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25183fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 25193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 25213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 25223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 25233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 25243fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25253fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 25263fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 25273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 25283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 25293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 25303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 25313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 25323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 25333fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 25343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 25353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 25365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 25375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25385baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 25395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 254017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 25410799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 25420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 25430799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 254417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 25455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 25461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2549f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 255017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2551f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2552898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2553bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2555bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2556898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 25571237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 25581237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 25591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 25605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 25615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2563db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 25652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2566db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 256717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2568db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2569db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25700799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2571db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2572db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2574db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 25755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2576db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2577db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 257863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 25795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 25805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 25835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 25845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 25855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25860799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2587a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2588063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2589063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2590063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2591063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2592063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2593063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2594063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2595063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 25965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2597200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 25982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 25992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 26000799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 26012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 26020799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2603aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 26050799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2606f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 26080799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2609f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 26110799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 26121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 26140799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2615aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 26170799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2618f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26190e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 26200e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 26210e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26220e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 26230e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26240e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 26252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 26262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26270e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 26280e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 26290e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26300e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26310e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 26322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 26332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26340e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 26350e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 26360e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 26394bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 26404bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 26415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 26431237c673c07f9d827129ba02720108816abde562Ted Kremenek 26441237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 264563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 264663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 264763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 26481237c673c07f9d827129ba02720108816abde562Ted Kremenek 26495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 265017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2651f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 26522333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2653f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 26542333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2655bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2656bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2657bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 26582333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 26591237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26601237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2662ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 26631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 26642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 26655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 26685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 26695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 26705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 26715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 26725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 26735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2674ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2675ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 26765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2677f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2678f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2679f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 268017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2681f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2682ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2683ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 26841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 26855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 26865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2688ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2689ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2690ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2691ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2692ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2693ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2694ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2695ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2696ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2697ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2698ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2699ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2700ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 27045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 270756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 270856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 270956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 271056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 271156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 271256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 271356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 271456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 271556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 271656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool TD, bool VD, 271756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 271856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 271956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 272056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, T, VK, OK, TD, VD, ContainsUnexpandedParameterPack), 272156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 272256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 272356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 272456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 272556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 272656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 272756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 272856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 272956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 273056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 273156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 273256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 273356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 273456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 273556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 273656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 273756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 273856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 273956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 274056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 274156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 274256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 274356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 274456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 274556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 274656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 274756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 274856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 274956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 275156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 275256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 27531237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 27545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 275556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 27575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 275847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 275956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 27600943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 276156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2762898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2763898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2764898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 276556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 276656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 276756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2768bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 276956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 277056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 277156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 27721237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 27731237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27741237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27751237c673c07f9d827129ba02720108816abde562Ted Kremenek } 27765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2777ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2778ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 277956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2780ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2781395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 278256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 27835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2784395a2abf0028968d85958610e393e067885dc14fTed Kremenek 278556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 278656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 27881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 279056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 279156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 27925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2793f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 279456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 27955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 279647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 279763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 27985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 27995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 28025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 28041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28051237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 280663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 280763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 280863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 28095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 281156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 281256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 281356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 281456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 281556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 281656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 281756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 281856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 282056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 282156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 282256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 282356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 282456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 282556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 282656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 282856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 282956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 283056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 283156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 283256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 283356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 283456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 283556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 283656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 283756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 283856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 283956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 284056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 284156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 284256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 284356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 284456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 284556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 284656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 284756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 284856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 284956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 285056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 285156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 285256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 285356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 285456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 285556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 285656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 285756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 285856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 285956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 286056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 286156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 286256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 286356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 286456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 286556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 286656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 286756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 286856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 286956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 287056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 287256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 287356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 287456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 287556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 287656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 287756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 287956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 288056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 288156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 288256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 288356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 288456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 288556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 288756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 288856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 288956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 289056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 289156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 289356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 289456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 289556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 289656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 289756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 289956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 290056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 290156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 290256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 290356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 290556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 290656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 290756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 290856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 290956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 29106481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 29116481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 29125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2913ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 29145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2915ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 29166481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2917bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false), 29182333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 29191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29207d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 29211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 29227d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 29237d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 29247d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 29257d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 29267d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 29277d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 29287d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 292963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 29305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 29315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2933ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 2934ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 29357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 29365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 29371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 29385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29396481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29411237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 294263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 29435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2944ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2945ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2946ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2947ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2948f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 2949f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 2950f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 2951ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 29525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2953ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2954ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 29552333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2956d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2957d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2958f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 2959bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor T->isDependentType(), false, false), 29602333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 29611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29626a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 29636a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 29646a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 29655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 29665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 29676a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 29686a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 296963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2970ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2971ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 29721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2973026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 29746a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2975026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 29766a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 29771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2978ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 29791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2980ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2981ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29831237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 298463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 2985ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2986ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2987d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2988d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2989d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2990d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2991d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2992d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2993d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2994d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2995d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2996d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2997d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2998d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2999d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3000d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 30015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3002d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3003d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3004d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3005a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3007bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 300894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 300994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 30101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 301194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 301294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 301394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 301494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 30151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 301694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 301794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 301894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 301963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3020d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3021d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3022d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 30231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3024d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3025d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3027d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3028d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3029d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3030d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 30311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3032aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3033aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3034aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 3035d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3036d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3037d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 30385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3039d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3040d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3041d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 30425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3043d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3045888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 304694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3047dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3048dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 30499a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 3050d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3052d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 305363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 305463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 305563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3056d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3057d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3058d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 30591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3060d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 30617976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 30627976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 30637976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 30647976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 30657976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 30667976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3067d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 30681237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 30695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3070d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3071d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3072f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3073f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3074ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3075bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3076bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3077bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3078bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 30791237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 30801237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 30811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 30821237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 30831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 30847976932a1c256d447316ffac58e9821417725e34Eli Friedman 308544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 308644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 308744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 30887976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 30897976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 30904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 30917976932a1c256d447316ffac58e9821417725e34Eli Friedman 30927976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 30937976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 30944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 30957976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 30967976932a1c256d447316ffac58e9821417725e34Eli Friedman } 30977976932a1c256d447316ffac58e9821417725e34Eli Friedman 30985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 309944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 31005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 310144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 31025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 310344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 310444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 310544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 310644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 310944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 31101237c673c07f9d827129ba02720108816abde562Ted Kremenek 311163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3112d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3113d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3114d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 31151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3116d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3117d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31191237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 312063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 312163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 312263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3123d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3124d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 31252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 31262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 31272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 31282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 31292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 31302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 31312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 31322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 31332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 31342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 31352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 31361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false), 3138f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 31392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 314044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 314144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 314244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 31432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 31442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 314544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 31462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 314763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 31492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 31502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 31522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 31532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 31541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 315663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 31572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 31582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 315974626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 31607c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 31615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 31622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 31637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 31647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 31652cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 31662cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3167f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3168bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3169bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3170bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 31712cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 31727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 31737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 317574626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3176d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3177d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 31785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 31795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3180d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3181d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 31822cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 31832cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 31842cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3185d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3186d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3188d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3189d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3190d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 319163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 31931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 31957c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 31967c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 31977c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 320063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 32017c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 32044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 32064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 32074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 32084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 32104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 32114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3212196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 32144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 32154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 32164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 32174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 32184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 32194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 32204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3221196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 32234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 32244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 32254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 32264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 32274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 32284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 32293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 32304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 32314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 32324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3233196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 32354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 32364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 32374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 32384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 32394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 324066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3241ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3242709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3243709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 324466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 32474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 32484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 32494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 32504423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 32514423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 32524423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 32534423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 32544423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 32554423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 32564423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 32574423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 32580bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3259a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3260a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3261a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3262a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 326366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3264709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3265709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3266ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3267d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3268d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3269709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3270709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 32711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3272ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 32731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3274aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3275aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3276aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 327716c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3278c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 328066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 32811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 328216c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3283c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 328566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3288c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 32899e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 32909e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3291c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3292fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3293709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 32941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 32964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 32974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 32984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 32994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 33004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 33014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 33024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 33044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 33054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 33064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 33084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3309fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3310709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3311c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 33124423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 33134423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 33144423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 33154423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 33164423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 33174423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33188cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 33198cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 33208cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 33213e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 33224423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 33230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 33240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 33250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 33260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 33270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 33280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 33294423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 33304423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 33314423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33328cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 33338cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 33348cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 33354423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 33364423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 33374423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33380bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3339c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3340c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3341b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3342b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3343b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 33441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3345d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3346d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3347d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 334887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 334987fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 33504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 33514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 33524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 33544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 33554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 33564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3357a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 33581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3359d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3360a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3361a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 336263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3363c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 336466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 33651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 336666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 336766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 33681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 336966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 337063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 337163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 337263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 337363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 33741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3375709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 33768111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3377709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 33788111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3380ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 33818111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3382ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 33838111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3384ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 33858111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3386ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 33878111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 33884423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 33894423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 33904423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 339166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 339266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 339305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 339405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 339505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 339605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 339705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 339805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 339905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 34001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 340105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 340205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 340305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 340405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 340505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 340605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 340705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 340805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 340905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 341005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 341105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 341205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 341305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3414ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3415ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3416ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3417ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3418ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 341905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 342005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 342105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 342205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3423eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 342405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3425eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 342605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 342705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 342805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 342905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3430ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3431ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3432ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3433ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 343405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 343505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 343605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 343705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 343805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3439ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3440319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3441ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3442eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 34439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 34449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 344505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3446d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3447d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3448d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3449d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 345005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 345105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 345205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 345305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 345405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 345505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 345605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 345705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 345805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 345905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 34601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 346205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 34631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 346505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 346605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 346705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 346805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 346905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 347005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 347105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 347205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 347305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 347405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 347505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 347605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 347705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 347805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 34791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 348005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 348105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 348205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 348305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 348405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 348505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 348605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 348705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 348805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 348905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 349005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 349105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 349205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 349305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 349405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 349505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 349605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 349705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 349805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 349905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 350005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 350105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 350205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 350305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 350405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3505ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3506ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 350705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 35091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 351005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 351105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 351205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 351305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 351405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 351505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 351605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 35171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 351805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 351905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 352005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 352105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 352205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 352305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 352405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 352505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 352605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 35271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 352805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 352905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 353005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 353105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 353205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 353305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 353405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 353505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 353605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 353705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 353805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 353905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3540b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 354105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3542b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 354305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 354405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 354505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 354605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 354705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 354805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 354905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 355005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 355105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 355205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 355305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 355405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 355587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 355687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 355787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 355887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 355987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 356005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 356105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 356305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 356405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 356505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 356605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 356705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 356805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 356905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 357005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 357205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 357305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 357805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 357905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 358005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 35824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3583d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3584d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3585d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3586d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3587d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3588d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 35894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 35904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 35914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 35924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 35934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 35944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 359524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 359624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 359724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 359824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 359924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 360024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 360105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 360205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3607eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3609d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3610d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 361105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 361205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 361305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 361405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3615b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3616ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 36171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 36181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3619ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 362005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3621b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3622b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3623b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3624b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3625b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3626b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3627cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3628cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3629cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3630cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3631cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3632cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3633cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3634cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3635cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3636b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3637b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3638b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3639b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3640b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3641b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3642b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3643b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3644b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3645711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3646711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3648319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3649d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 365005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 365105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 365205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 365305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3657d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3660eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3661eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3662d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 366305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 366405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 36651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 366605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 366705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 366805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 366905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 367005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 367105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 367205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3673d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3674d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3675d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3676d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3677d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3678d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3679d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3680d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3681d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3682d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3683d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3684d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3685d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3686d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3687d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3688d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3689d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3690d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3691d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3692d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3693ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3694ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3695319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3696ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3697ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 369824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 369924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 370063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 370105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 370205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 37031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 370405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 370505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 370605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 370705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 370863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 370963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 371063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 371163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 37123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 37133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 37143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 37153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 37163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 37171a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 37181a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 37193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 37201a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 37211a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 37221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 37233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 37241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3725f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3726bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, false, false) { } 37273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3728d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3729d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3730d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3731d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 37321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 37333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 37343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 37353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 37363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 373763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 37383498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 37393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 37403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 37413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 374263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 37452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 37472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 37482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 37492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 37502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 37521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 37532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 37542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 375637bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 37571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 37591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 37612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 37622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 37632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 37641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 37662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 37672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 37682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 37692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 377083ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 37711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 37732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 37742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 377563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 37762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 37771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 37782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 37791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 37802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 37812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 37821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 378463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 378563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 378663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 378737bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 378860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 37893397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 37902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 37912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3793f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// \brief Represents a C1X generic selection. 3794f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3795f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling 3796f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3797f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3798f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3799f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3800f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3801f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3802f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3803f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3804f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3805f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3806f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3807f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3808f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3809f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3810f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3811f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3812f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3813f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3814f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3815f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3816f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3817f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3818f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3819f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3820f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3821f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3822f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3823f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3829f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3830f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 3834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 3836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3839f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3840f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3841f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 3842f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3843f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 3844f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 3845f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3846f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 3847f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3848f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 3849f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 3850f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 3851f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3852f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 3853f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 3854f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3855f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 3856f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3857f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 3858f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 3859f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3860f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 3861f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3862f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 3863f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 3864f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 3865f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 3866f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 3867f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3868f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3869f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 3870f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 3871f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3872f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 3873f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3874f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 3875f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 3876f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3877f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 3878f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 3879f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3880f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 3881f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 3882f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 3883f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3884f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3885f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 3886f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3887f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 3888f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 3889f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3890f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 3891f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 3892f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3893f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 3894f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 3895f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3896f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 3897f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3898f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 3899f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 3900f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3901f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3902f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 3903f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 3904f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 39054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 39074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3909a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3910a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3911a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3912a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3913a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 391473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 391573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 391673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3917a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3918a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3919d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3920a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3921a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3922f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 3923f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 39240943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 39250943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 3926bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 3927bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 3928d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3930d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3931d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3932d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3933d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3934a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3935a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3936d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3937d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3938d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3939d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3940d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3941d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3942d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3943d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3944a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3945a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 39461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3947a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3948a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3949a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 39501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3951a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3952a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3953a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 39541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 395563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3956a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3957a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 39581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39592140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 39602140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 39612140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 39621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 39641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3965a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3966a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 39671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3968a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 396963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 3970a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3971a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3972a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 397356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 39749c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 39754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 397656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 397756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 39784eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3979469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 3980f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 3981bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType(), false, false), 3982469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 39839c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 398484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 398584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 398684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3987d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 398856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 398984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 399084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 399156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 399256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 399356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 399456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 39959c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 399663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 399756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 39989c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 39999c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 400056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 400156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 400256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 40031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40049c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 40054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 40064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 40071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 400963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 40104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 40111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40126b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 40136b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 40144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 40156b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 40164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 40177d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 40187d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 40194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 40206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 40216b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 402294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 402394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 402494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 402594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 402694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 40271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40286b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 40296b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 40306b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 403194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 403294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 403394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 403494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 403563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 40361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 403894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 40391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40407d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 40417d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 404289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 40431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 40454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 40464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 40471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 404963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 40504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 40514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 405261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 405361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 405461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 405561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerclass AsTypeExpr : public Expr { 405661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 405761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner Expr* SrcExpr; 405861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner QualType DstType; 405961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 406061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 406161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 406261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 406361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 406461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 406561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner : Expr(AsTypeExprClass, DstType, VK, OK, false, false, false), 406661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SrcExpr(SrcExpr), DstType(DstType), 406761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 406861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 406961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// \brief Build an empty __builtin_astype 407061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 407161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 407261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 407361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner Expr *getSrcExpr() const { return SrcExpr; } 407461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner QualType getDstType() const { return DstType; } 407561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 40767b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 407761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 407861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 407961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 408061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 408161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return T->getStmtClass() == AsTypeExprClass; 408261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 408361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 408461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 408561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 408661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner child_range children() { return child_range(); } 408761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 40885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 40895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 40905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4091