Expr.h revision 5baba9d98364a3525d6afa15a04cdad82fd6dd30
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 25525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 263b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 27b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 28c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 31590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 32c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 368e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 39409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 42833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 43d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 46f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 55bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner virtual void ANCHOR(); // key function. 569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected: 571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// TypeDependent - Whether this expression is type-dependent 58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 59898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ValueDependent - Whether this expression is value-dependent 62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// ValueKind - The value classification of this expression. 665baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// Only actually used by certain subclasses. 675baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned ValueKind : 2; 685baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall enum { BitsRemaining = 28 }; 70f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T, bool TD, bool VD) 725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall : Stmt(SC), TypeDependent(TD), ValueDependent(VD), ValueKind(0) { 73898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 74898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 75898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 760b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 770b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 780b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 8043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Increases the reference count for this expression. 8143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 8243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// Invoke the Retain() operation when this expression 8343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// is being shared by another owner. 8443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Expr *Retain() { 8543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Stmt::Retain(); 8643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor return this; 8743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor } 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 919d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 929d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 969d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 979d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 98905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 998320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 100f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 1029d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 10377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValueDependent(bool VD) { ValueDependent = VD; } 1150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 123898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 125898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 126898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 127898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 128898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setTypeDependent(bool TD) { TypeDependent = TD; } 1310b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 142026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 143026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 144026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 145026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 146df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 15708ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 15876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 164fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 16586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1662514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 167e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 168e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 17028be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 17153202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 17744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 17844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 17944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 18044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 185fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 187ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1904f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1915daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 192ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 19386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 1942514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 195e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 196e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 19844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 19944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief classify - Classify this expression according to the C++0x 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief classifyModifiable - Classify this expression according to the 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 28933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 29033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 29133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 29438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 29538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 297093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 298093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3002b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3012b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3022b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3032b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3042b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 310590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 311590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 313590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3148070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 315590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 317c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 318c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3194204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 32294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3232d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 32494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 32794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 32894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 33194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 33294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 33394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 33494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 33594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 33694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 33794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 33894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 33994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 34094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 343e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 344e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 345e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 346e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 347e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 348e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 349e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 350e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 351e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 35294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 35394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 3546ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 355019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 356019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 357019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 3585b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 3595b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 360cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 361cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 362cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 363cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 364cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 3656ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 36645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 36745b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 368c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 3696ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// which must be evaluated each time and must not be optimization away 3716ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 3726ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 373393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian bool HasSideEffects(ASTContext &Ctx) const; 374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 37551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 37651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 37751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 37851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 379b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 380b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 3811b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 3821b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 383e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 384e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 385e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 386ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 387ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 388ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 389ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 390ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 392ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 393ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 394ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 396ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 397ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 398ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 399ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 401efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 402efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 403efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 404ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 405ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 406efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 40744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 409102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4114e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 4134e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 4144e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 4152b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 41656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 41756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 41827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 41956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4212fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 4222fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 4232fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 4242fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 425ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 426ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 427ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 428ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 4316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 4326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 4346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 4356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 4366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 4376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 438c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// \brief Determine whether this expression directly creates a 4402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// temporary object (of class type). 4412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor bool isTemporaryObject() const { return getTemporaryObject() != 0; } 4422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 4432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// \brief If this expression directly creates a temporary object of 4442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// class type, return the expression that actually constructs that 4452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// temporary object. 4462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor const Expr *getTemporaryObject() const; 4472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 4482b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 4494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 4504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 45156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 45256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 45356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 454ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 455ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 456ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 458898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 459898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 460898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 475a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 476a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 477a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 479a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 482a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 485a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 488c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 491c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 492a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 495a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 496c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 499833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 500a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 501c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 503833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 504833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 506d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 507d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 508d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 5098dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 510d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 512c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 517c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 520c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 525c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // DecoratedD - The declaration that we are referencing, plus two bits to 526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // (2) the declaration's name was followed by an explicit template 528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 529dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 5302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 5339e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// DNLoc - Provides source/type location info for the 5352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in DecoratedD. 5362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 5372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 5402cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 544a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 545c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 550096832c5ed5b9106fa177ebc148489760c3bc496John McCall 551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 552dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 553d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 5540da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T); 555663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 5562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 5572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 5582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 5592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T); 5602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 561663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 562663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 563663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 5660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 5670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 5689e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 570dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 5710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) { 5720da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 5730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 578dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 5800da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 5810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 582663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 5832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 5842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NestedNameSpecifier *Qualifier, 5852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 5862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 5872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 5882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 5892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 5902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 591663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 592663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 593663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis bool HasQualifier, unsigned NumTemplateArgs); 594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 595dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 596dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 597dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 598904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 5992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 6002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 6012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 6022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 6039e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 6040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 607a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 609a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 611a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 612a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 613a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 614a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 618a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 619a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 620c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// \brief If the name was qualified, retrieves the nested-name-specifier 622a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 623a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 627a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 628a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 630096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 631096832c5ed5b9106fa177ebc148489760c3bc496John McCall return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); 632096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 633096832c5ed5b9106fa177ebc148489760c3bc496John McCall 634096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 635096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 636096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 637096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 638096832c5ed5b9106fa177ebc148489760c3bc496John McCall 639096832c5ed5b9106fa177ebc148489760c3bc496John McCall if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 640096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 641096832c5ed5b9106fa177ebc148489760c3bc496John McCall 642096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 643096832c5ed5b9106fa177ebc148489760c3bc496John McCall getNameQualifier() + 1); 644096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 645096832c5ed5b9106fa177ebc148489760c3bc496John McCall 646096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 647096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 648096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 649096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 650a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 651d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 652096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 653096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 654096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 655096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 656096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 657096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 658096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 659096832c5ed5b9106fa177ebc148489760c3bc496John McCall 660d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 661d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 662d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 663096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 664096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 665d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 666c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 667a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 668a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 669a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 670096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 671a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 672c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 673096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 674a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 675c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 676a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 677a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 678833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 679096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 680a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 681c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 682096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 683a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 684c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 685a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 686a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 687a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 688096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 690c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 691096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 693c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 696a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 697096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 700096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 701a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 702c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 70499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 70977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 71077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 711663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 71260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 7133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 716d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 717d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 718227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 719227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 720227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 721227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 722848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 723848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 724848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 725848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 726227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 7271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 728227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 729227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 730227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 731227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 733c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Expr(PredefinedExprClass, type, type->isDependentType(), 734773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson type->isDependentType()), Loc(l), Type(IT) {} 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 73817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 73917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 740227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 74117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 74217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 74317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 74417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 74517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 746848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 7473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 748227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 749227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 752227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 753d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 75677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 75777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 758227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 759227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 7672333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) { 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 770a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 7710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IntegerLiteral(EmptyShell Empty) 7730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 7740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 778313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 779313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 780313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 7810b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 7820b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 7830b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 79077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 79177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 797c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 800c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 8012333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l), 8022333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsWide(iswide) { 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 8060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 8070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 808018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 809c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 8121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 8160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 8170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 8180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 82377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 82477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 82577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 82677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 830525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 831720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FloatingLiteral(const llvm::APFloat &V, bool isexact, 835720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 8362333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(FloatingLiteralClass, Type, false, false), Value(V), 8372333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsExact(isexact), Loc(L) {} 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 83917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 8401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 84117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 84217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 843c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 84417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setValue(const llvm::APFloat &Val) { Value = Val; } 84517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 846720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 84717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 848c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 849da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 850da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 851da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 852da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 85517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 85617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 86577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 86677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 8705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 8715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 8725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 8735d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 8745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 8755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 8765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 8775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 8782333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {} 8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 880cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 882cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 883cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 8845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 8855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 886cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 887cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 8885d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 8915d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 8925d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 8931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 8955d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 8965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 8975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 8985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 899e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 900e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 901e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 902a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 903c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 904c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 905690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 906690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 9078bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 908690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 909c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 910c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 911c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 912c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 913c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 914c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 919726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 920726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 9212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 9222333f7727f97018d6742e1e0938133bcfad967abEli Friedman StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {} 9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 9262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 9272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 9282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 929a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 9302085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 9312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 9332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 9342085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 9352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 9362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 937a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 938673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 939673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 940673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 941b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 942b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 943b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 9442f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 946673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 947673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 948b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 949673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 951673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 952673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 9538d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 954b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 955b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 956b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 95733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 95833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 95933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 960726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 961726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 962726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 964726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 965726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 966726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 967726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 969673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 970673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 971673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 972673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 973b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 974b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 975b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 98677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 98777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 9945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 997898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 999898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1001c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1003c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1004c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 10055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 10065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1007c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1008c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 1009866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1011313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1012313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1013c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1014313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1015313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1016313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1017c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1018313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 102577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 102677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 10310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1033dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1034dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1035dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1036dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1037dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1038dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1039dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 10435baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PostInc = UO_PostInc; 10445baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PostDec = UO_PostDec; 10455baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PreInc = UO_PreInc; 10465baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PreDec = UO_PreDec; 10475baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode AddrOf = UO_AddrOf; 10485baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Deref = UO_Deref; 10495baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Plus = UO_Plus; 10505baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Minus = UO_Minus; 10515baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Not = UO_Not; 10525baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode LNot = UO_LNot; 10535baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Real = UO_Real; 10545baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Imag = UO_Imag; 10555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Extension = UO_Extension; 10565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 10585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 10649103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 1065de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 10679103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 10710b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 10720b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 10740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 10750b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 10770b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 10780b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 10810b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 10820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 10842085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 10852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 10862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10885a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 10892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 10902085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 10912085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 10925a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 10935a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 10955d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isArithmeticOp() const { return isArithmeticOp(Opc); } 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1104bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1105bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1106bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1107bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1108bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1109bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1110bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1111bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 112677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 112777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 11318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 11328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 11338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 11348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1135c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 11368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 11378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 11388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 11398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 11408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 11418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1142c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 11438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 11458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 11468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 11478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 11488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 11498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 11508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1151cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 11528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1153cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 11548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1155cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1156cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1157cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1158cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1159cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 11608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 11618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 11638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1164c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 11668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 11698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1170c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 11718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 11728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 11738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 11748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1175c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1176cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 11778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1178c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 11808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1181c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 11828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 11838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1186c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 11878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1188c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 11898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1190c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 11938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 11958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1196cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1197cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1198cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1199cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1200c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1202c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1205c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 12098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 12108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 12118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 12148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 12158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1216cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 12178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1218c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 12208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 12218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1223cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1224cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1225cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1226c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1227cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1228c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 12308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 12318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 12328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 12348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 12358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange getRange() const { return Range; } 12368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 12418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 12428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 12438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 12448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 12458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 12468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1247c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1248c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 12498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1250c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 12518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 12528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 12538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 12558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1256c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 12578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1259c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1261c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 12638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 12648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1266c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 12708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 12718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 12728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 12748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 12758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1276c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 12788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 12798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 12818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 12828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1283c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const OffsetOfNode &getComponent(unsigned Idx) { 12858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 12868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 12878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1293c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 13028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 13058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 13088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1309c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 13118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual SourceRange getSourceRange() const { 13158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 13168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 13198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_begin(); 13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_end(); 13278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13290518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 13300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 13310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 13320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 13330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1334d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1335a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1336d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1337d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 133942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1341a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 13420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 13430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 13442850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 1345ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 13462850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1347a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TInfo->getType()->isDependentType()), 1348ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1349a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1350ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1351ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1353ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1354ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1355ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 1356ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1357ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1358ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1359ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1360ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1361d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 13620518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 13630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 13640b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 13650b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 13660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 13680b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 13690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 13710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 13725ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 13735ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1374a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 13750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 13765ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 13770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1378caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 13790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1380d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 13810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1382caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1383caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1384caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 13850b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13860b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1387a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1388a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 13900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 13910b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 13920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 13930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 13940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 13950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 13960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 13970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 139876e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 13990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 14000b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 14020b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1403866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1404866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1405866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1406866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 141477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 141577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 142477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14282324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 142973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 14302850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 14312850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 14322850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 14332850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 143473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 143573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 143673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1438cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1439cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1440cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1441cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 14422324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 14432324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 14442324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 14452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 14462324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 144733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 144833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 144933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 145033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 14515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 14525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1453cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1454cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 14555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 14565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1457cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 14605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 146177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 14645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 14652324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 14685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 14692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 14725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 147677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1479026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1480cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1481cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 14825cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 149077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 149177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1495b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1497b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 14981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1499b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1500b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 150277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 15035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1507b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1508b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1509668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1510668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 151142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 15125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15161f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1517ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 15181f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 15195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 15205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 152118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1522a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1523d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1524d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1525d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1526d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1527d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1528a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1529a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1530bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1531bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1532bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1533a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 15345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 15355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 15415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 15455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1548934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1549934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1550934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1551934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1552934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1554d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1555d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1556d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 15578189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 15605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1562d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1563d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 15645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 15655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1571cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1572cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 15733c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 15776dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 15786dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1580d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 15811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1582866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 158477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 15855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15884bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 15894bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 159288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 159377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 159477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 159577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1598ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 16016bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 16026bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1603161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 16046bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 16056bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1606ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1607ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 16085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1610ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1611ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1612f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1614ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 16182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 16192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 16202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1621ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 162283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 162483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 16256bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 16266bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1627c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 16286bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1630c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1631c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1632c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1633c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 16346bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1635c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 16386bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 16396bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 16406bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 164183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 164283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 164383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 16446bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1645c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1646c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 16471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1649f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 16502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, QualType ty) 16512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Expr(MemberExprClass, ty, 16522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara base->isTypeDependent(), base->isValueDependent()), 16532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 16542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 16552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 16562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 16572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 16582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 16592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 16602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 16612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 16622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 16632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1664f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceLocation l, QualType ty) 16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 1666ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 16672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 16682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 16696bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1670510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 167283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 1673161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 16742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 1675d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1676c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty); 16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 16795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 168057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 168157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 168257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 168357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 168457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1685f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1686f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 16871f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 16886bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1689161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 16906bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1691161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1692161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 16936bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 16946bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 16956bb8017bb9e828d118e15e59d71c66bba323c364John McCall 16961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 16970979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 16980979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 16996bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 170283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 170383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 17056bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 170683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 17071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 170983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 171283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 171383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 17156bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 171683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 171883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 171983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1720c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1721c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1722c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1723096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 17241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1725c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1727d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1728d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1729d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1730096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1731096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1732096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1733096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1734096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1735096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 1736096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 1737096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1738096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 1739096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 1740096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1741096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1742096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 1743096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 1744096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1745096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1746096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1747096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 1748096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 1749096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1750096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 1751096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1752096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1753096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 1754096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 1755096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 1756096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 1757096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 1758096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 1759d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 1760c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1762c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 17631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1764c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1765c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1767096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 1768c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1770c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1771c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 1772833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1773c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 17741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1776096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 1777c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1779c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1780c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1782c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1785096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1786c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1789c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1791c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1792c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 17931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1794096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 1795c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 17982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 17992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 18002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 18012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 18022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 18041f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 18051f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1806ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1807ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1808026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 18091f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 18105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 181272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 181372527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 18142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation EndLoc = (HasExplicitTemplateArgumentList) 18152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ? getRAngleLoc() : getMemberNameInfo().getEndLoc(); 18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 181872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1819c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1820c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 18215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 182683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 18275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 18291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18301237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 18311237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 18321237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1836aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1837aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 18380fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 18390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 18400fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 18410fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 18421d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 18431d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 18441d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 184542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 18465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1847e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1848aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 18492333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can compound literals be value-dependent? 185042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 18511d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall QualType T, Expr *init, bool fileScope) 18521d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall : Expr(CompoundLiteralExprClass, T, 185342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall tinfo->getType()->isDependentType(), false), 185442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 18551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1856ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1857ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1858ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1859ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 18605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 18615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1862ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1863e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1864e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1865ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1866ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 18670fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1868ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1869ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 187042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 187142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 187242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 187373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 18740fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 18750fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 18760fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 18770fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 187873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 18790fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 188073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1881aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1884aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1885aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18871237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 18881237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 18891237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1890aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1891aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 189249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 189349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 189449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 189549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 18960835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 1897cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 18985baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19005baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_Unknown - Unknown cast kind. 19015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// FIXME: The goal is to get rid of this and make all casts have a 19025baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// kind so that the AST client doesn't have to try to figure out what's 19035baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// going on. 19045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_Unknown = clang::CK_Unknown; 19055baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19065baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_BitCast - Used for reinterpret_cast. 19075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_BitCast = clang::CK_BitCast; 190811de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson 19095baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_LValueBitCast - Used for reinterpret_cast of expressions to 19105baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// a reference type. 19115baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_LValueBitCast = clang::CK_LValueBitCast; 19125baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19135baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_NoOp - Used for const_cast. 19145baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_NoOp = clang::CK_NoOp; 19151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19165baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_BaseToDerived - Base to derived class casts. 19175baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_BaseToDerived = clang::CK_BaseToDerived; 191823cba801e11b03929c44f8cf54578305963a3476John McCall 19195baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_DerivedToBase - Derived to base class casts. 19205baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_DerivedToBase = clang::CK_DerivedToBase; 19211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19225baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_UncheckedDerivedToBase - Derived to base class casts that 19235baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// assume that the derived pointer is not null. 19245baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_UncheckedDerivedToBase 19255baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_UncheckedDerivedToBase; 19261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19275baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_Dynamic - Dynamic cast. 19285baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_Dynamic = clang::CK_Dynamic; 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19305baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_ToUnion - Cast to union (GCC extension). 19315baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_ToUnion = clang::CK_ToUnion; 19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_ArrayToPointerDecay - Array to pointer decay. 19345baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_ArrayToPointerDecay 19355baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_ArrayToPointerDecay; 19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19375baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall // CK_FunctionToPointerDecay - Function to pointer decay. 19385baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_FunctionToPointerDecay 19395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_FunctionToPointerDecay; 19409099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian 19415baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_NullToMemberPointer - Null pointer to member pointer. 19425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_NullToMemberPointer 19435baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_NullToMemberPointer; 19447fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian 19455baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 19465baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// member pointer in derived class. 19475baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_BaseToDerivedMemberPointer 19485baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_BaseToDerivedMemberPointer; 194982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 19505baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 19515baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// member pointer in base class. 19525baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_DerivedToBaseMemberPointer 19535baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_DerivedToBaseMemberPointer; 19545baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_UserDefinedConversion - Conversion using a user defined type 19565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// conversion function. 19575baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_UserDefinedConversion 19585baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_UserDefinedConversion; 19595baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19605baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_ConstructorConversion - Conversion by constructor 19615baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_ConstructorConversion 19625baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_ConstructorConversion; 19635baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19645baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_IntegralToPointer - Integral to pointer 19655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_IntegralToPointer = clang::CK_IntegralToPointer; 19665baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19675baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_PointerToIntegral - Pointer to integral 19685baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_PointerToIntegral = clang::CK_PointerToIntegral; 19695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19705baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_ToVoid - Cast to void. 19715baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_ToVoid = clang::CK_ToVoid; 19725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19735baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_VectorSplat - Casting from an integer/floating type to an extended 19745baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// vector type with the same element type as the src type. Splats the 19755baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// src expression into the destination expression. 19765baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_VectorSplat = clang::CK_VectorSplat; 19775baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19785baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_IntegralCast - Casting between integral types of different size. 19795baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_IntegralCast = clang::CK_IntegralCast; 19805baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19815baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_IntegralToFloating - Integral to floating point. 19825baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_IntegralToFloating = clang::CK_IntegralToFloating; 19835baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19845baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_FloatingToIntegral - Floating point to integral. 19855baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_FloatingToIntegral = clang::CK_FloatingToIntegral; 19865baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19875baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_FloatingCast - Casting between floating types of different size. 19885baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_FloatingCast = clang::CK_FloatingCast; 19895baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19905baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_MemberPointerToBoolean - Member pointer to boolean 19915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_MemberPointerToBoolean 19925baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_MemberPointerToBoolean; 19935baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19945baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c 19955baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// pointer 19965baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_AnyPointerToObjCPointerCast 19975baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_AnyPointerToObjCPointerCast; 19985baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 19995baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block 20005baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// pointer 20015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_AnyPointerToBlockPointerCast 20025baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_AnyPointerToBlockPointerCast; 20035baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 20045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// \brief Converting between two Objective-C object types, which 20055baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// can occur when performing reference binding to an Objective-C 20065baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// object. 20075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const CastKind CK_ObjCObjectLValueCast 20085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall = clang::CK_ObjCObjectLValueCast; 20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2010cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 2011f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned Kind : 5; 2012f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned BasePathSize : BitsRemaining - 5; 20130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2014409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 20157ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson void CheckBasePath() const { 2016409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2017409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 20185cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2019cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2020cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2021409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2022409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2023f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2024f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2025409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2026409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2027409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Unknown: 2028409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2029e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor case CK_LValueBitCast: 2030409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NoOp: 2031409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2032409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2033409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2034409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2035409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2036409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_UserDefinedConversion: 2037409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2038409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2039409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2040409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2041409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2042409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2043409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2044409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2045409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2046409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_MemberPointerToBoolean: 2047409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2048409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2049569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 2050f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2051409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2052409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2053409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2054409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2055409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2056f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2057f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2058f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2059f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2060f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 20610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2062409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op, 2063f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned BasePathSize) : 2064898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 2065898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2067898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2068898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2069898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 2071f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Kind(kind), BasePathSize(BasePathSize), Op(op) { 2072f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CheckBasePath(); 2073f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2075087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2076f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 2077f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : Expr(SC, Empty), BasePathSize(BasePathSize) { } 20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20790835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 2080f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind getCastKind() const { return static_cast<CastKind>(Kind); } 2081cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson void setCastKind(CastKind K) { Kind = K; } 2082f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2083f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 20840835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 20850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2086087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2087087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 20886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 20896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 20906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 20916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 20926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 20936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 20946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 209541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2096f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2097f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 2098f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall bool path_empty() const { return BasePathSize == 0; } 2099f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned path_size() const { return BasePathSize; } 2100f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2101f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2102f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2103f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2104f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2105f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 210641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 21071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21084bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 21094bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 21100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 21110835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 21140835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 21150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 21160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 21170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 211849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 211949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 212049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 212149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 212249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2123bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2124bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2125906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2126bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2127bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2128bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2129bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2130906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2132906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2133906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2134906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2135906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2136bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2137bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 21380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2139906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2140f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 21415baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 21425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePathLength) { 21435baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ValueKind = VK; 21445baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 214590045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2146087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2147f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2148f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2149f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2150f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2151f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2152f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 21535baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 21545baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall : CastExpr(ImplicitCastExprClass, ty, kind, op, 0) { 21555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ValueKind = VK; 21565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2157f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2158f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2159f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2160f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 21615baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2162f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2163f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2164087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 21650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 21660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 21670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 216890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 21695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// getValueKind - The value kind that this cast produces. 21705baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind getValueKind() const { 21715baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall return static_cast<ExprValueKind>(ValueKind); 21725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2173eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 21745baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall /// setValueKind - Set the value kind this cast produces. 21755baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall void setValueKind(ExprValueKind Cat) { ValueKind = Cat; } 2176eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 217949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 218049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 218149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 218249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 218349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 218549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 218649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 218749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 218849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 218949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 219049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 219249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 219349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 219449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 219549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 219649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2197906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2198906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 21990835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 22009d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 22019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 22029d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 220349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 220449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2205c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 2206f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy) 2207f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, exprTy, kind, op, PathSize), TInfo(writtenTy) {} 220849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2209db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2210f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2211f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2212db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 221349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 22149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 22159d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 22169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 22179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 22189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 221949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 222049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 22219d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 222249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22244bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 22254bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 222649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 222749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 222849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 222949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 22306eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 223149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 223249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 22336eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2234b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2235b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 22379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, 2238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 223941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, PathSize, 224141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 224249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2243db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, CastKind K, 2249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2252f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2253f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2254db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2255b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2256db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2257db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2258b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2259db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2260db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 2262b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 22635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 22665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22676eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 22713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22723fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 22733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 22743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 22753fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 22763fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22773fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 22783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 22793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 22803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 22813fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 22823fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 22833fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 22843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 22853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 22863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 22873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 22885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 22895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 22905baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 22915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 22925baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PtrMemD = BO_PtrMemD; 22935baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode PtrMemI = BO_PtrMemI; 22945baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Mul = BO_Mul; 22955baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Div = BO_Div; 22965baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Rem = BO_Rem; 22975baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Add = BO_Add; 22985baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Sub = BO_Sub; 22995baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Shl = BO_Shl; 23005baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Shr = BO_Shr; 23015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode LT = BO_LT; 23025baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode GT = BO_GT; 23035baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode LE = BO_LE; 23045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode GE = BO_GE; 23055baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode EQ = BO_EQ; 23065baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode NE = BO_NE; 23075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode And = BO_And; 23085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Xor = BO_Xor; 23095baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Or = BO_Or; 23105baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode LAnd = BO_LAnd; 23115baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode LOr = BO_LOr; 23125baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Assign = BO_Assign; 23135baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode MulAssign = BO_MulAssign; 23145baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode DivAssign = BO_DivAssign; 23155baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode RemAssign = BO_RemAssign; 23165baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode AddAssign = BO_AddAssign; 23175baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode SubAssign = BO_SubAssign; 23185baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode ShlAssign = BO_ShlAssign; 23195baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode ShrAssign = BO_ShrAssign; 23205baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode AndAssign = BO_AndAssign; 23215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode XorAssign = BO_XorAssign; 23225baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode OrAssign = BO_OrAssign; 23235baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall static const Opcode Comma = BO_Comma; 23245baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 232517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 232617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 23275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 232817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 232917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 233217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 233317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2334898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 2335898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 2337898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 23381237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 23391237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 23401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 23415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 23425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2344db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 2346db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 2347db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 234817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2349db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2350db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 2352db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2353db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2355db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 23565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2357db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2358db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 23605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 23615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 23645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 23655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2367a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek const char *getOpcodeStr() const { return getOpcodeStr(Opc); } 2368a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2369063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2370063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2371063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2372063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2373063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2374063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2375063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2376063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 23775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 23785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 2379ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose static bool isAdditiveOp(Opcode Opc) { return Opc == Add || Opc == Sub; } 2380ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose bool isAdditiveOp() const { return isAdditiveOp(Opc); } 238140a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; } 238240a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek bool isShiftOp() const { return isShiftOp(Opc); } 2383aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 2384aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; } 2385aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isBitwiseOp() const { return isBitwiseOp(Opc); } 2386f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 2387f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 2388f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 2389f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 2391f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2393aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; } 2394aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isComparisonOp() const { return isComparisonOp(Opc); } 2395aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 2396f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 2397f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 2398f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 24005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 24015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 24021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 24044bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 24054bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 24065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 24081237c673c07f9d827129ba02720108816abde562Ted Kremenek 24091237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 24101237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 24111237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 24121237c673c07f9d827129ba02720108816abde562Ted Kremenek 24135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 241417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 24152333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 24162333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CompoundAssignOperatorClass, ResTy, 24172333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 24182333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isValueDependent() || rhs->isValueDependent()), 24192333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 24201237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24211237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2423ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 24241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 2425ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(SC, Empty), Opc(MulAssign) { } 24265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 24325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 24345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2435ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2436ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 24375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 2439ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 2440ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 244117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 244217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 2443ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2444ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 24475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2449ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2450ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2451ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2452ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2453ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2454ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2455ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2456ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2457ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2458ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2459ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2460ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2461ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 24625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 24631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 24641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 24695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 24705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 24715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 24721237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 24735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 247447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 24755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 247647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 247747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation CLoc, Expr *rhs, QualType t) 2478898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 2479898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2480898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2481898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 2482898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 2484898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 248547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 248647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 248747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 24881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 24891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 24911237c673c07f9d827129ba02720108816abde562Ted Kremenek } 24925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2493ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2494ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 2495ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 2496ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2497395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 2498395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 24995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2500ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 2501395a2abf0028968d85958610e393e067885dc14fTed Kremenek 2502395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2503395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 2504395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 2505395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 2506395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 25071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // is only evaluated once. 2508395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 25095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 2510395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 25111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2512395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2513395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 25145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 25151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 2517ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2518ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 25195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2520ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 25215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 252247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 252347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 252447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 252547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 252647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 252747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 25285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 25295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 25305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 25335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25361237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25371237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25381237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 25395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25416481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 25426481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 25445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 25455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25466481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 25476481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 25482333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(AddrLabelExprClass, t, false, false), 25492333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 25537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 25547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25557d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 25567d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 25577d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 25587d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 25597d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 25615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 25625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 25657d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 25667d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25706481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25721237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25731237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25741237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 25755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2576ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2577ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2578ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2579ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2580ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 25815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2582ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2583ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 25842333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2585d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2586d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 25872333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(StmtExprClass, T, T->isDependentType(), false), 25882333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 25891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25906a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 25916a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 25926a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 25935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 25945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 25956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 25966a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2597ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2598ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2599ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 26001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2601026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 26026a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2603026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 26046a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 26051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2606ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 26071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2608ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2609ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 26101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26111237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 26121237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 26131237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2614ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2615ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2616dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2617d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2618d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2619d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2620d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 26213fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo1; 26223fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo2; 2623363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2624d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 26251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 26263fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2, 26273fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara SourceLocation RP) : 26282333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(TypesCompatibleExprClass, ReturnType, false, false), 26293fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TInfo1(tinfo1), TInfo2(tinfo2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2630d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 263144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 263244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 263344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 263444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 26353fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo1() const { return TInfo1; } 26363fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; } 26373fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo2() const { return TInfo2; } 26383fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; } 26393fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara 26403fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType1() const { return TInfo1->getType(); } 26413fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType2() const { return TInfo2->getType(); } 26421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 264344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 264444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 26451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 264644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 264744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 26481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2649d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2650363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2651d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2652d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 26531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2654d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2655d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 26561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26571237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 26581237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 26591237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2660d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2661d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2662d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2663d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2664d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2665d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2666d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2667d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2668d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2669d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2670d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2671d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2672d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2673d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2674d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 26755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2676d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2677d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2678d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 26792333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 26802333f7727f97018d6742e1e0938133bcfad967abEli Friedman // to be computed differently? 2681a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 26821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 26842333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false), 26852333f7727f97018d6742e1e0938133bcfad967abEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 26861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2687a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2688d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2689d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2690d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 269194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 269294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 26931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 269494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 269594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 269694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 269794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 269994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 270094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 270194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2702d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2703d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2704d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 27061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2707d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2710d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2711d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 27185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 27225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2723d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2725888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 272694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2727dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2728dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 27299a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2730d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 27311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2732d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2733d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2734d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2735d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2736d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2737d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2739d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 27407976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 27417976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 27427976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 27437976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 27447976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 27457976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2746d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 27471237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 27485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2749d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2750d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2751d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2752ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2753ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 27541237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 27551237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 27561237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27571237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27597976932a1c256d447316ffac58e9821417725e34Eli Friedman 276044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 276144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 276244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 27637976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 27647976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 276527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 27667976932a1c256d447316ffac58e9821417725e34Eli Friedman 27677976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 27687976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 27697976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 27707976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 27717976932a1c256d447316ffac58e9821417725e34Eli Friedman } 27727976932a1c256d447316ffac58e9821417725e34Eli Friedman 27735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 277444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 27755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 277644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 27775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 277844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 277944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 278044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 278144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 27821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 278444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 27851237c673c07f9d827129ba02720108816abde562Ted Kremenek 2786d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2787d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2788d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2789d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2791d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2792d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 27931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27941237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 27951237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 27961237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2797d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2798d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 27992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 28002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 28012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 28022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 28032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 28042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 28052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 28062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 28072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 28082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 28092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 28101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 28112333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { } 28122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 281344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 281444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 281544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 28162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 28172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 281844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 28192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 28202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 28212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 28222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 28232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 28252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 28262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 28271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 28292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 28302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 28312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 28322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 283374626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 28347c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 28355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 28362cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 28377c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 28387c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 28392cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 28402cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 28412333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(VAArgExprClass, t, t->isDependentType(), false), 28422cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 28437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 28447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 28451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 284674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 2847d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2848d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 28505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2851d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2852d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28532cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 28542cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 28552cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 2856d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2857d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 28581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2859d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2860d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2861d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28627c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 28637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 28667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 28677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 28687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 28691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 28717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 28721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 28737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 28764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 28784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 28794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 28804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 28824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 28834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2884196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 28864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 28874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 28884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 28894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 28904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 28914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 28924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2893196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 28954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 28964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 28974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 28984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 28994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 29004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 29013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 29024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 29034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 29044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2905196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 29064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 29074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 29084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 29094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 29104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 29114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 291266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 2913ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 2914709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 2915709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 291666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 29171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 29194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 29204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 29214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 29220bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 29230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 29240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 29250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2926a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2927a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2928a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2929a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 293066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 2931709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 2932709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 2933ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 2934d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2935d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2936709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 2937709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2939ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getInit(unsigned Init) const { 2942c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 294466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 29451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getInit(unsigned Init) { 2947c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 294966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2952c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29539e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 29549e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2955c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2956fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2957709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 29581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 29604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 29624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 29634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 29644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 29654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 29664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 29674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 29684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 29694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 29704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 29724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 29734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 2974709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 2975c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 29760bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 29770bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 29780bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 29790bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 29800bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 29810bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 29820bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 29830bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 29840bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2985c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2986c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2987b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2988b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2989b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 29901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2991d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2992d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2993d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 299487fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 299587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 29964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 29974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 29984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 30004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 30014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 30024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3003a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3005d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3006a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3007a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 300866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 300966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 30101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 301166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 301366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 301466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 30151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 301666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 301766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 301866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 30191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3020709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 30218111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3022709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 30238111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 30241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3025ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 30268111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3027ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 30288111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3029ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 30308111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3031ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 30328111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 303366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 303466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 303505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 303605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 303705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 303905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 304005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 304105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 30421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3056ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3057ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3058ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3059ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3060ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 306405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3065eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3067eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 306805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 306905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 307005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 307105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3072ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3073ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3074ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3075ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 307605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 307705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 307805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 307905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 308005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3081ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3082319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3083ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3084eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 30859ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 30869ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3088d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3089d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3090d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3091d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 309505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 31021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 310405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 31051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 310705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 311105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 311905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 312005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 312605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 312705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 312805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 312905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 313005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 313105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 313205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 313305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 313505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 313605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 313705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 314405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 314505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 314605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3147ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3148ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 314905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 31501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 315205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 315305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 315405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 315505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 315605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 315705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 316005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 316205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 316505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 316805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 31691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 317205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 317505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 317805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 317905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 318005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 318105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 319405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 319505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 319887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 319987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 320087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 320187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 320305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 320405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 320505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 320605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 320705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 320805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 320905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 321005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 321105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 321205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 321305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 321405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 321505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 321605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 321705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 321805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 321905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 322005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 322105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 322205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 32244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3225d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3226d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3227d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3228d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3229d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3230d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 32314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 32324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 32334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 32344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 32354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 32364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 324005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 324105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 324205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3243eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 324405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3245d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3246d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 324705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 324805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 324905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 325005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 325105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 3252ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 32531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 32541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3255ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 325605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3257711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3258711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3259c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3260319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3261d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 326205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 326305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 326405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 326505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 326605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 326705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 326805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3269d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 327005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 327105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3272eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3273eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3274d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 327505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 327605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 32771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 327805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 327905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 328005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 328105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 328205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 328305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 328405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3285d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3286d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3287d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3288d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3289d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3290d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3291d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3292d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3293d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3294d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3295d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3296d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3297d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3298d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3299d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3300d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3301d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3302d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3303d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3304d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3305ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3306ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3307319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3308ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3309ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 331005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 331105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 331205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 33131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 331405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 331505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 331605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 331705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 331805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 33191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 33203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 33213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 33233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 33243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 33251a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 33261a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 33273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 33281a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 33291a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 33301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 33313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 33332333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImplicitValueInitExprClass, ty, false, false) { } 33343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3335d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3336d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3337d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3338d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 33403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 33413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 33423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 33433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33443498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 33453498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 33463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 33473498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 33493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 33501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 335105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 335205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 33532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 33552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 33562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 33572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 33582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 33601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 33612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 33622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 336437bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 33651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 33671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 33692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 33702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 33712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 33742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 33752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 33762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 337883ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 33812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 33822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 33842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 33851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 33862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 33871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 33882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 33901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 33922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 33932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 339437bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 339560adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 33963397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 33972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 33982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 34014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 34024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 34034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3404a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3405a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3406a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3407a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3408a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 340973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 341073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 341173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3412a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3413a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3414d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3415a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3416a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3417a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 3418a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 34192333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(), 34202333f7727f97018d6742e1e0938133bcfad967abEli Friedman base->isValueDependent()), 3421d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3423d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3424d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3425d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3426d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3427a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3428a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3429d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3430d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3431d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3432d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3433d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3434d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3435d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3436d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3437a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3438a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 34391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3440a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3441a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3442a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 34431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3444a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3445a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3446a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 34471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3448a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 3449a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3450a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 34511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34522140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 34532140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 34542140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 34551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 34571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3458a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3459a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 34601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3461a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 3462a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 3463a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 3464a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3465a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3466a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 346756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 34689c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 34694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 347056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 347156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 3472b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 34734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3474b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 34752333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockExprClass, ty, ty->isDependentType(), false), 3476b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 34779c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 347884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 347984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 348084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3481d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 348256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 348384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 348484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 348556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 348656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 348756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 348856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 34899c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 34909c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 349156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 34929c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 34939c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 349456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 349556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 349656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 3497b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 34985b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 3499b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 350084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3501b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 35039c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 35044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 35054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 35084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 35094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 35104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 35111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 35134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 35144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 35151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 35164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 35177d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 35187d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 351989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Stmt *CopyConstructorVal; 35204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 35212333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Fix type/value dependence! 35221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 352389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian bool constAdded = false, 352484ca008a462b515f63871253f494d53c9190363cFariborz Jahanian Stmt *copyConstructorVal = 0) 352584ca008a462b515f63871253f494d53c9190363cFariborz Jahanian : Expr(BlockDeclRefExprClass, t, (!t.isNull() && t->isDependentType()),false), 352652bc56a296b11b4fc6bf5ddf4ded5262f6484bdbFariborz Jahanian D(d), Loc(l), IsByRef(ByRef), 352789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian ConstQualAdded(constAdded), CopyConstructorVal(copyConstructorVal) {} 352894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 352994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 353094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 353194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 353294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 35331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 35354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 353694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 353794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 353894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 353994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 354094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 35414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 35421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 354494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 35451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35467d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 35477d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 354889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 354989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian const Expr *getCopyConstructorExpr() const 355089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 355189f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Expr *getCopyConstructorExpr() 355289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 355389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; } 355494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 35561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 35574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 35584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 35591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 35614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 35624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 35634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 35644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 35655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 35665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 35675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3568