Expr.h revision 8e6285af719adc6f86d6faa235d22a08eb68ee3a
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. 565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Expr(StmtClass SC, QualType T, bool TD, bool VD) : Stmt(SC) { 598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueKind = 0; 62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 650b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 660b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 688e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// getValueKind - The value kind that this cast produces. 698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprValueKind getValueKind() const { 708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 728e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall /// setValueKind - Set the value kind this cast produces. 748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 77f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 86905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 878320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 88f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 1028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setValueDependent(bool VD) { ExprBits.ValueDependent = VD; } 1030b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setTypeDependent(bool TD) { ExprBits.TypeDependent = TD; } 1190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 130026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 131026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 132026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 133026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 134df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 14508ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 14676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 152fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 15386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1542514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 155e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 156e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 15828be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 15953202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 16544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 16644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 16744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 16844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 173fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 175ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1784f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1795daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 180ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 18186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 1822514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 183e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 184e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 18644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 18744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 1902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 1912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 1922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 1932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 1942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 1952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 1962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 1972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 1982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 1992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 2032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 244369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 260369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 27733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 27833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 27933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 28238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 28338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 285093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 286093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 287c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 2892b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 2902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 2912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 2922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 293c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 298590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 299590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 301590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3028070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 303590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 305c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 306c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3074204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 31094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3112d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 31294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 31594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 31694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 31994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 32094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 32194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 32294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 32394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 32494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 32594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 32694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 32794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 32894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 331e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 332e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 333e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 334e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 335e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 336e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 337e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 338e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 339e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 34094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 34194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 3426ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 343019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 344019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 345019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 3465b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 3475b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 348cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 349cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 350cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 351cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 352cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 3536ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 35445b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 35545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 356c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 3576ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 358138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 3596ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 3606ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 361393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian bool HasSideEffects(ASTContext &Ctx) const; 362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 36351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 36451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 36551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 36651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 367b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 368b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 3691b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 3701b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 371e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 372e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 373e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 374ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 375ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 376ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 377ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 378ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 379c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 380ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 381ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 382ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 383c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 384ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 385ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 386ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 387ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 389efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 390efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 391efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 392ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 393ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 394efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 39544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 397102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 400369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 401369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 402369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 403369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 404369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 405369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 406369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 407369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 408369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 4094e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 4114e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 4124e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 4132b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 41456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 41556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 41627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 41756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 4181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4192fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 4202fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 4212fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 4222fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 4234d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 4244d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 4254d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 4264d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 427ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 428ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 429ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 430ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 4336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 4346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 435c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 4366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 4376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 4386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 4396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 440c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 441558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 442558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 443558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 4442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 4452b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 4464e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 4474e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 44856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 44956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 45056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 451ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 452ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 453ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 455898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 456898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 457898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 470a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 471a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 472a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 476a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 477a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 478a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 479a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 482a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 488c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 491a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 492a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 493c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 495833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 496833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 498c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 499a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 500833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 501833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 503d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 504d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 505d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 5068dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 507d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 508a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 509c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 514c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 517c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // DecoratedD - The declaration that we are referencing, plus two bits to 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // (2) the declaration's name was followed by an explicit template 525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 526dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 5272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 5309e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// DNLoc - Provides source/type location info for the 5322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in DecoratedD. 5332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 5342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 536a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 5372cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 540a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 544a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 545a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 547096832c5ed5b9106fa177ebc148489760c3bc496John McCall 548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 549dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 550d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 5510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T); 552663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 5532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 5542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 5552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 5562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T); 5572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 558663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 559663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 560663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 561c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 5630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 5640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 5659e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 567dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 5680da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) { 5690da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 5700da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 573a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 574a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 575dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 5770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 5780da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 579663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 5802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 5812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NestedNameSpecifier *Qualifier, 5822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 5832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 5842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 5852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 5862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 5872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 588663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 589663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 590663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis bool HasQualifier, unsigned NumTemplateArgs); 591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 592dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 593dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 594dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 595904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 5962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 5972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 5982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 5992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 6009e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 6010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 602a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 604a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 606a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 607c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 609a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 610a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 611a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 612a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 613a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 614c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 618c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// \brief If the name was qualified, retrieves the nested-name-specifier 619a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 620a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 621a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 622a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 623c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 627096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 628096832c5ed5b9106fa177ebc148489760c3bc496John McCall return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); 629096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 630096832c5ed5b9106fa177ebc148489760c3bc496John McCall 631096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 632096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 633096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 634096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 635096832c5ed5b9106fa177ebc148489760c3bc496John McCall 636096832c5ed5b9106fa177ebc148489760c3bc496John McCall if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 637096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 638096832c5ed5b9106fa177ebc148489760c3bc496John McCall 639096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 640096832c5ed5b9106fa177ebc148489760c3bc496John McCall getNameQualifier() + 1); 641096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 642096832c5ed5b9106fa177ebc148489760c3bc496John McCall 643096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 644096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 645096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 646096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 647a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 648d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 649096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 650096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 651096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 652096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 653096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 654096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 655096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 656096832c5ed5b9106fa177ebc148489760c3bc496John McCall 657d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 658d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 659d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 660096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 661096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 662d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 663c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 664a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 665a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 666a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 667096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 668a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 669c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 670096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 671a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 672c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 673a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 674a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 675833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 676096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 677a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 678c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 679096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 680a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 681c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 682a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 683a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 684a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 685096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 686a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 687c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 688096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 690c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 691a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 693a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 694096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 696c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 697096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 70199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 70677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 70777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 708663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 70960adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 7103397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 713d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 714d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 715227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 716227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 717227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 718227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 719848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 720848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 721848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 722848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 723227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 7241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 725227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 726227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 727227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 728227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 730c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Expr(PredefinedExprClass, type, type->isDependentType(), 731773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson type->isDependentType()), Loc(l), Type(IT) {} 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 73517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 73617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 737227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 73817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 73917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 74017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 74117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 74217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 743848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 7443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 745227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 746227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 749227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 750d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 75377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 75477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 755227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 756227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 7589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 7599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 7609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 7619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 7629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 7639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 7649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 7659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 7669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 7679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 7689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 7699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 7709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 7719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 7739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 7759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 7769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 7789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 7799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 7819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 7829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 7839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 7849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 7859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 7869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 7879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 7889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 7899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 7919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 7929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 7939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 7949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 7959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 7969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 7979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 7989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 7999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 8009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 8019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 8029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 8039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 8059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 8099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 8109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 8119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 8159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 8169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 8179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, type, false, false), Loc(l) { 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 8199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 821a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 8229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 8239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // or UnsignedLongLongTy 8249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 8259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 8269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 8270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 831313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 832313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 833313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 8349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 8350b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 8360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 84277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 84377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 84477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 850c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 853c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 8542333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l), 8552333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsWide(iswide) { 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8580b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 8590b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 8600b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 861018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 862c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 8690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 8700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 8710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 87677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 87777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 87877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 87977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 8839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 884720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 888720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 8899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Type, false, false), 8909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 8919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 8929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 89417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 8969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 89717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 8989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 8999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 9009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 9019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 9029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 9049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 9059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 9069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 90717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 908720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 90917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 910c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 911da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 912da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 913da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 914da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 91717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 91817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 92777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 92877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9315d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 9325d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 9335d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 9345d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 9355d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 9365d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 9375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 9385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 9395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 9402333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {} 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 942cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 944cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 945cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 9465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 9475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 948cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 949cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 9505d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 9535d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 9545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9565d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 9575d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 9585d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 9595d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 9605d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 961e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 962e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 963e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 964a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 965c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 966c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 967690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 968690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 9698bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 970690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 971c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 972c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 973c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 974c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 975c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 976c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 981726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 982726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 9832085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 9842333f7727f97018d6742e1e0938133bcfad967abEli Friedman StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {} 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9872085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 9882085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 9892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 9902085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 991a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 9922085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 9932085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 9952085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 9962085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 9972085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 9982085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 999a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1000673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1001673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1002673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1003b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1004b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1005b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 10062f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1008673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1009673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1010b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1011673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 1013673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 1014673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 10158d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1016b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1017b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1018b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 101933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 102033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 102133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1022726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1023726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1024726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1026726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1027726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1028726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1029726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1031673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1032673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1033673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 1034673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1035b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1036b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1037b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 104877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 104977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 10565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1059898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 1061898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1063c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1065c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1066c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 10675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 10685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1069c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1070c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 1071866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1073313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1074313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1075c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1076313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1077313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1078313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1079c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1080313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 108777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 108877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 10930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1095dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1096dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1097dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1098dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1099dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1100dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1101dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 11055baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 11070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11090799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 11139103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 1114de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 11160799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 11202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 11210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11220799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 11230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 11240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 11260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 11270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 11300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 11310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 11332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 11342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 11352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11375a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 11382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 11392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 11402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 11415a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 11420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 11430799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 11442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1145993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 11462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 11472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1148993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 11492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 11502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 11512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 11522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 11530799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1159bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1160bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1161bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1162bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1163bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1164bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1165bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1166bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 118177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 118277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 11868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 11878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 11888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 11898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1190c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 11918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 11938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 11948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 11958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 11968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1197c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 11988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 11998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 12008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 12028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1206cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1208cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 12098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1210cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1211cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1212cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1213cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1214cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 12158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 12168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 12188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1219c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 12218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 12248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 12268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 12278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 12288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 12298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1230c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1231cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 12328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 12358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1236c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 12388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1241c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 12428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 12448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1245c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 12478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 12488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1249c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 12508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1251cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1252cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1253cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1254cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1257c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 12588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 12598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 12628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 12638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 12648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 12668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 12708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1271cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 12728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1273c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 12758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 12768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1277c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1278cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1279cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1280cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1281c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1282cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1283c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 12858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 12868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 12878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1288c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 12898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange getRange() const { return Range; } 12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1294c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1303c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 13068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 13088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1314c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1315c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1316c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1317c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 13188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 13198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1321c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 13278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 13298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 13308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1331c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 13338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 13348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 13368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 13378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1338c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const OffsetOfNode &getComponent(unsigned Idx) { 13408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 13428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 13458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 13478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 13508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 13518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 13548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 13568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 13578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 13628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1364c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual SourceRange getSourceRange() const { 13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_begin(); 13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_end(); 13828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 13838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 13850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 13860518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 13870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 13880518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1389d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1390a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1391d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1392d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 139442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1396a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 13970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 13980518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 13992850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 1400ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 14012850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1402a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TInfo->getType()->isDependentType()), 1403ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1404a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1405ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1406ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1408ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1409ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1410ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 1411ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1412ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1413ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1414ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1415ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1416d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 14170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 14180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 14190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 14200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 14210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 14230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 14240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 14260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 14275ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 14285ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1429a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 14300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 14315ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 14320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1433caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 14340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1435d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 14360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1437caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1438caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1439caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 14400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1442a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1443a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 14450b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 14460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14470518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 14480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 14490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 14500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 14510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 14520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 145376e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 14540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 14550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 14570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1458866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1459866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1460866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1461866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14660518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 146977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 147077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 147977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14832324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 148473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 14852850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 14862850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 14872850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 14882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 148973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 149073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 149173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 14921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1493cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1494cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1495cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1496cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 14972324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 14982324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 14992324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 15002324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 15012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 150233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 150333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 150433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 150533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 15065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 15075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1508cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1509cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 15105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 15115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1512cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 15155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 151677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 15195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 15202324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 15235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 15242324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 15275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 15291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 153177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1534026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1535cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1536cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 15375cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 154477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 154577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 154677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1550b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1552b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1554b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1555b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 155777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 15585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1562b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1563b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1564668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1565668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 156642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15711f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1572ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 15731f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 15745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 15755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 157618b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1577a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1578d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1579d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1580d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1581d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1582d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1583a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1584a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1585bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1586bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1587bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1588a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 15965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 16005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1603934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1604934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1605934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1606934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1607934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1609d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1610d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1611d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 16128189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 16155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1617d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1618d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 16195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 16205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1626cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1627cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 16283c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 16326dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 16336dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1635d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 16361f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1637866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 163977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 16405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16434bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 16444bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 164788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 164877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 164977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 165077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1653ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 16566bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 16576bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1658161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 16596bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 16606bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1661ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1662ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 16635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1665ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1666ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1667f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1669ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 16732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 16742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 16752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1676ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 167783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 16806bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 16816bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1682c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 16836bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1685c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1686c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1687c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1688c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 16896bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1690c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 169283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 16936bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 16946bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 16956bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 169683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 169783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 169883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 16996bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1700c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1701c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1704f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 17052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, QualType ty) 17062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Expr(MemberExprClass, ty, 17072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara base->isTypeDependent(), base->isValueDependent()), 17082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 17092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 17102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 17112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 17122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 17132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 17142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 17152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 17162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 17172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 17182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1719f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceLocation l, QualType ty) 17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 1721ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 17222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 17232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 17246bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1725510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 172783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 1728161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 17292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 1730d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1731c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty); 17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 17345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 173557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 173657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 173757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 173857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 173957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1740f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1741f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 17421f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 17436bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1744161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 17456bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1746161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1747161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 17486bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 17496bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 17506bb8017bb9e828d118e15e59d71c66bba323c364John McCall 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 17520979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 17530979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 17546bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 175783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 175883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 17591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 17606bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 176183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 176383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 176483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 176783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 176883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 17691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 17706bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 177183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 177383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 177483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1775c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1776c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1777c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1778096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1780c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1782d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1783d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1784d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1785096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1786096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1787096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1788096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1789096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1790096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 1791096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 1792096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1793096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 1794096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 1795096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1796096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1797096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 1798096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 1799096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1800096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1801096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1802096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 1803096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 1804096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1805096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 1806096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1807096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1808096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 1809096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 1810096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 1811096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 1812096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 1813096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 1814d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 1815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1817c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1819c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1820c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1822096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 1823c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1825c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1826c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 1827833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1828c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 18291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1831096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 1832c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1834c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1835c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1837c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1840096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1841c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1844c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1846c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1847c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1849096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 1850c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 18532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 18542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 18552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 18562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 18572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 18591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 18601f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1861ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1862ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1863026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 18641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 186772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 186872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 18692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation EndLoc = (HasExplicitTemplateArgumentList) 18702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ? getRAngleLoc() : getMemberNameInfo().getEndLoc(); 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 187272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 187372527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1874c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1875c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 188183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18851237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 18861237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 18871237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 18884045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 18894045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 18904045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 18915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1894aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1895aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 18960fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 18970fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 18980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 18990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 19001d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 19011d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 19021d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 190342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 19045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1905e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1906aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 19072333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can compound literals be value-dependent? 190842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 19091d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall QualType T, Expr *init, bool fileScope) 19101d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall : Expr(CompoundLiteralExprClass, T, 191142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall tinfo->getType()->isDependentType(), false), 191242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1914ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1915ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1916ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1917ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 19185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 19195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1920ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1921e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1922e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1923ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1924ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 19250fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1926ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1927ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 192842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 192942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 193042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 193173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 19320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 19330fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 19340fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 19350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 193673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 19370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 193873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1939aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1942aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1943aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 19441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19451237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 19461237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 19471237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1948aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1949aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 195049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 195149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 195249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 195349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 19540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 1955cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 19565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1958cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 19590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 1960409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 19617ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson void CheckBasePath() const { 1962409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 1963409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 19645cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 1965cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 1966cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 1967409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 1968409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 1969f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 1970f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 1971409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 1972409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 1973409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Unknown: 1974409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 1975e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor case CK_LValueBitCast: 1976409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NoOp: 1977409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 1978409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 1979409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 1980409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 1981409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 1982409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_UserDefinedConversion: 1983409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 1984409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 1985409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 1986409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 1987409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 1988409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 1989409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 1990409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 1991409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 1992409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_MemberPointerToBoolean: 1993409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 1994409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 1995569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 1996f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 1997409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 1998409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 1999409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2000409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2001409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2002f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2003f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2004f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2005f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2006f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 20070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2008409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op, 2009f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned BasePathSize) : 2010898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 2011898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2012898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2013898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2014898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2015898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 20178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 20188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 20198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 2020f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CheckBasePath(); 2021f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2023087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2024f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 20258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 20268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 20278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 20281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20290835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 20308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 20318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2032f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2033f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 20340835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 20350835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2036087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2037087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 20386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 20396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 20406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 20416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 20426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 20436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 20446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 204541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2046f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2047f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 20488e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 20498e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2050f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2051f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2052f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2053f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2054f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2055f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 205641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 20571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20584bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 20594bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 20600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 20610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 20640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 20650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 20660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 20670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 206849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 206949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 207049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 207149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 207249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2073bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2074bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2075906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2076bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2077bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2078bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2079bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2080906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2082906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2083906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2084906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2085906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2086bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2087bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 20880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2089906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2090f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 20915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 20925baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePathLength) { 20938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall setValueKind(VK); 20945baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 209590045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2096087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2097f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2098f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2099f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2100f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2101f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2102f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 21035baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 21045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall : CastExpr(ImplicitCastExprClass, ty, kind, op, 0) { 21058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall setValueKind(VK); 21065baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2107f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2108f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2109f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2110f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 21115baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2112f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2113f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2114087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 21150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 21160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 21170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 211890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 21198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall using Expr::getValueKind; 21208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall using Expr::setValueKind; 2121eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 21221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 212449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 212549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 212649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 212749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 212849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 213049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 213149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 213249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 213349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 213449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 213549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 213749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 213849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 213949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 214049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 214149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2142906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2143906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 21440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 21459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 21469d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 21479d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 214849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 214949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2150c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 2151f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy) 2152f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, exprTy, kind, op, PathSize), TInfo(writtenTy) {} 215349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2154db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2155f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2156f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2157db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 215849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 21599d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 21609d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 21619d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 21629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 21639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 216449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 216549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 21669d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 216749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 21681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21694bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 21704bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 217149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 217249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 217349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 217449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 21756eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 217649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 217749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 21786eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2179b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2180b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2181f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 21829d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, 2183f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 218441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2185f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, PathSize, 218641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 218749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2188db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2189f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2190f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2191f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2193f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, CastKind K, 2194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2196f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2197f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2198f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2199db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2200b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2201db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2202db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2203b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2204db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2205db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 2207b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 22115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22126eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 22135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22153fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 22163fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22173fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 22183fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 22193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 22203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 22213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 22233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 22243fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 22253fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 22263fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 22273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 22283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 22293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 22303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 22313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 22323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 22345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 22355baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 22365baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 223717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 22380799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 22390799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 22400799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 224117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 22425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 22441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 224517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 224617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2247898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 2248898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 22491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 2250898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 22511237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 22521237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 22531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 22545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 22555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2257db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 22592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2260db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 226117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2262db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2263db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22640799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2265db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2266db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2268db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 22695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2270db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2271db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 22735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 22745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 22785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22800799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2281a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2282063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2283063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2284063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2285063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2286063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2287063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2288063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2289063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 22905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2291200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 22922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 22932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 22940799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 22952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 22960799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2297aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 22982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 22990799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2300f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 23020799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2303f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 23050799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 23080799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2309aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 23102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 23110799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2312f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isAssignmentOp() const { return Opc >= BO_Assign && Opc <= BO_OrAssign; } 23142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isCompoundAssignmentOp() const { 23152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 23162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 23172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isShiftAssignOp() const { 23182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 23192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 23201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 23224bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 23234bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 23245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 23261237c673c07f9d827129ba02720108816abde562Ted Kremenek 23271237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 23281237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 23291237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 23301237c673c07f9d827129ba02720108816abde562Ted Kremenek 23315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 233217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 23332333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 23342333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CompoundAssignOperatorClass, ResTy, 23352333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 23362333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isValueDependent() || rhs->isValueDependent()), 23372333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 23381237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 23391237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 23405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2341ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 23432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 23445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 23505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 23525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2353ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2354ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 23555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 2357ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 2358ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 235917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 236017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 2361ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2362ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 23645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 23655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2367ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2368ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2369ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2370ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2371ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2372ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2373ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2374ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2375ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2376ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2377ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2378ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2379ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 23805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 23811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 23821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 23835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 23855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 23875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 23885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 23895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 23901237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 23915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2392f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Stmt* Save; 239347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 239547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 2396f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian SourceLocation CLoc, Expr *rhs, Expr *save, QualType t) 2397898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 2398898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2399898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2400898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 2401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 24021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 2403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 240447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 240547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 240647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 24071237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 24081237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24091237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 2410f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Save = save; 24111237c673c07f9d827129ba02720108816abde562Ted Kremenek } 24125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2413ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2414ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 2415ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 2416ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2417395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 2418395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 24195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2420ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 2421395a2abf0028968d85958610e393e067885dc14fTed Kremenek 2422395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2423f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // expression if the condition evaluates to true. 2424395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 2425af9b96828f9126d993c3e155b8453be62013b735Fariborz Jahanian return cast<Expr>(SubExprs[LHS]); 2426395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2428ae2777cfe7d21f73e5a4155082fe20197cec62bdNick Lewycky // getFalseExpr - Return the subexpression representing the value of the ?: 2429395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 24305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2431f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 2432f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // getSaveExpr - In most cases this value will be null. Except a GCC extension 2433f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // allows the left subexpression to be omitted, and instead of that condition 2434f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // be returned. e.g: x ?: y is shorthand for x ? x : y, except that the 2435f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // expression "x" is only evaluated once. Under this senario, this function 2436f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // returns the original, non-converted condition expression for the ?:operator 2437f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getSaveExpr() const { return Save? cast<Expr>(Save) : (Expr*)0; } 2438f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 2439f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getLHS() const { return Save ? 0 : cast<Expr>(SubExprs[LHS]); } 2440ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2441ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 24425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2443ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 24445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2445f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getSAVE() const { return Save? cast<Expr>(Save) : (Expr*)0; } 2446f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian void setSAVE(Expr *E) { Save = E; } 2447f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 244847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 244947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 245047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 245147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 245247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 245347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 24545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24621237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 24631237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 24641237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24676481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 24686481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 24695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 24705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 24715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 24726481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 24736481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 24742333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(AddrLabelExprClass, t, false, false), 24752333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 24761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24777d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 24797d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 24807d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 24817d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 24827d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 24837d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 24847d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 24857d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 24865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 24875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 24885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 24917d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 24927d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 24935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 24941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 24955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24966481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24981237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 24991237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25001237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2502ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2503ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2504ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2505ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2506ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 25075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2508ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2509ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 25102333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2511d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2512d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 25132333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(StmtExprClass, T, T->isDependentType(), false), 25142333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 25151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25166a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 25176a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 25186a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 25195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 25205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 25216a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 25226a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2523ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2524ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2525ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2527026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 25286a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2529026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 25306a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2532ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 25331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2534ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2535ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 25361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25371237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25381237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25391237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2540ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2541ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2542dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2543d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2544d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2545d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2546d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 25473fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo1; 25483fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo2; 2549363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2550d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 25511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 25523fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2, 25533fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara SourceLocation RP) : 25542333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(TypesCompatibleExprClass, ReturnType, false, false), 25553fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TInfo1(tinfo1), TInfo2(tinfo2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2556d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 255744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 255844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 255944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 256044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 25613fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo1() const { return TInfo1; } 25623fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; } 25633fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo2() const { return TInfo2; } 25643fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; } 25653fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara 25663fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType1() const { return TInfo1->getType(); } 25673fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType2() const { return TInfo2->getType(); } 25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 256944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 257044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 257244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 257344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2575d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2576363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2577d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2578d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 25791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2580d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2581d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25831237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25841237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25851237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2586d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2587d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2588d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2589d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2590d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2591d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2592d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2593d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2594d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2595d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2596d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2597d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2598d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2599d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2600d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 26015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2602d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2603d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2604d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 26052333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 26062333f7727f97018d6742e1e0938133bcfad967abEli Friedman // to be computed differently? 2607a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 26081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 26102333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false), 26112333f7727f97018d6742e1e0938133bcfad967abEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 26121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2613a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2614d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2615d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2616d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 261794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 261894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 262094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 262194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 262294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 262394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 26241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 262594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 262694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 262794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2628d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2629d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2630d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2631d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 26321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2633d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2634d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2636d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2637d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2638d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2639d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 26401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2641d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2642d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2643d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 26445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2645d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2646d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2647d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 26485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2649d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 26501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2651888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 265294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2653dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2654dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 26559a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2656d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 26571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2658d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2659d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2660d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2661d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2662d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2663d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2665d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 26667976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 26677976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 26687976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 26697976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 26707976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 26717976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2672d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 26731237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 26745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2675d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2676d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2677d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2678ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2679ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 26801237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 26811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 26821237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26831237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 26857976932a1c256d447316ffac58e9821417725e34Eli Friedman 268644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 268744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 268844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 26897976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 26907976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 269127437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 26927976932a1c256d447316ffac58e9821417725e34Eli Friedman 26937976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 26947976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 26957976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 26967976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 26977976932a1c256d447316ffac58e9821417725e34Eli Friedman } 26987976932a1c256d447316ffac58e9821417725e34Eli Friedman 26995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 270044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 27015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 270244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 27035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 270444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 270544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 270644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 270744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 27081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 271044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 27111237c673c07f9d827129ba02720108816abde562Ted Kremenek 2712d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2713d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2714d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2715d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 27161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2717d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2718d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27201237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 27211237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 27221237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2723d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2724d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 27252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 27262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 27272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 27282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 27292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 27302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 27312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 27322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 27332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 27342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 27352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 27361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 27372333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { } 27382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 273944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 274044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 274144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 27422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 27432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 274444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 27452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 27462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 27472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 27482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 27492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 27512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 27522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 27531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 27552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 27562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 27572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 27582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 275974626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 27607c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 27615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 27622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 27637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 27647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 27652cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 27662cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 27672333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(VAArgExprClass, t, t->isDependentType(), false), 27682cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 27697c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 27707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 27711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 277274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 2773d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2774d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 27755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 27765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2777d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2778d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 27792cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 27802cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 27812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 2782d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2783d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 27841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2785d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2786d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2787d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 27887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 27897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 27927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 27937c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 27947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27967c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 27977c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 27981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 27997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 28024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 28044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 28054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 28064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 28084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 28094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2810196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 28124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 28134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 28144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 28154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 28164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 28174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 28184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2819196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 28214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 28224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 28234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 28244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 28254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 28264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 28273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 28284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 28294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 28304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2831196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 28334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 28344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 28354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 28364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 28374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 283866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 2839ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 2840709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 2841709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 284266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 28431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 28454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 28464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 28474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 28480bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 28490bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 28500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 28510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2852a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2853a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2854a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2855a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 285666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 2857709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 2858709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 2859ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 2860d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2861d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2862709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 2863709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2865ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 286716c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 2868c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 28694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 287066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 28711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287216c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 2873c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 28744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 287566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2878c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 28799e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 28809e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2881c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2882fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2883709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 28841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 28864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 28874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 28884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 28894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 28904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 28914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 28924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 28934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 28944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 28954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 28964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 28974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 28984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 28994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 2900709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 2901c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 29020bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 29030bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 29040bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 29050bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 29060bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 29070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 29080bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 29090bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 29100bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2911c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2912c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2913b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2914b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2915b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 29161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2917d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2918d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2919d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 292087fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 292187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 29224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 29234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 29244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 29264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 29274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 29284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2929a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 29301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 2931d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 2932a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 2933a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 293466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 293566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 29361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 293766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 293966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 294066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 294266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 294366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 294466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 29451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2946709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 29478111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 2948709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 29498111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2951ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 29528111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 2953ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 29548111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 2955ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 29568111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 2957ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 29588111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 295966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 296066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 296105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 296205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 296305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 296405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 296505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 296605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 296705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 29681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 296905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 297005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 297105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 297205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 297305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 297405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 297505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 297605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 297705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 297805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 297905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 298005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 298105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 2982ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 2983ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 2984ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 2985ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2986ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 298705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 298805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 298905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 299005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2991eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 299205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 2993eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 299405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 299505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 299605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 299705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2998ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 2999ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3000ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3001ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 300205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 300305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 300405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 300505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 300605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3007ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3008319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3009ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3010eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 30119ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 30129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 301305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3014d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3015d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3016d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3017d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 301805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 301905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 302005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 302105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 302205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 302305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 302405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 302505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 302605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 302705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 30281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 302905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 303005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 30311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 303305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 303405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 303505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 303605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 303705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 303905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 304005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 304105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 304205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 305605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 305905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 306005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 306405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 306505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 306705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 306805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 306905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 307005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 307105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 307205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3073ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3074ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 307505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 30761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 30771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 307805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 307905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 308005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 308105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 30851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 308805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 308905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 309005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 309105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 310305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 310405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 310505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 310605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 310705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 311105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 311905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 312005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 312105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 312387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 312487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 312587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 312687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 312787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 312805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 312905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 313005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 313105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 313205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 313305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 313505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 313605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 313705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 314405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 314505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 314605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 314705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 314805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 314905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 31504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3151d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3152d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3153d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3154d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3155d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3156d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 31574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 31584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 31594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 31604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 31614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 31624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 31651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 316805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3169eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3171d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3172d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 317505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 3178ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 31801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3181ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3183711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3184711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3185c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3186319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3187d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 319405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3195d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3198eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3199eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3200d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 320105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 32031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 320405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 320505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 320605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 320705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 320805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 320905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 321005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3211d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3212d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3213d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3214d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3215d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3216d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3217d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3218d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3219d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3220d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3221d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3222d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3223d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3224d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3225d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3226d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3227d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3228d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3229d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3230d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3231ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3232ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3233319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3234ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3235ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 323605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 324005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 324105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 324205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 324305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 324405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 32463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 32473498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 32483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 32493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 32503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 32511a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 32521a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 32533498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 32541a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 32551a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 32573498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 32581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 32592333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImplicitValueInitExprClass, ty, false, false) { } 32603498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3261d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3262d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3263d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3264d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 32651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 32663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 32673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 32683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 32693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 32703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 32713498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 32723498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 32733498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 32743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 32753498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 32761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 327705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 327805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 32792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 32802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 32812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 32822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 32832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 32842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 32852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 32872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 32882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 32892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 329037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 32911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 32931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 32952ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 32962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 32972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 32981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 33002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 33012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 33022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 330483ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33062ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 33072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 33082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 33102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 33111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 33122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 33131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 33142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 33161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 33182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 33192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 332037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 332160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 33223397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 33232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 33242ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 33274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 33284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 33294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3330a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3331a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3332a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3333a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3334a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 333573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 333673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 333773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3338a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3339a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3340d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3341a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3342a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3343a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 3344a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 33452333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(), 33462333f7727f97018d6742e1e0938133bcfad967abEli Friedman base->isValueDependent()), 3347d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 33481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3349d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3350d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3351d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3352d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3353a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3354a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3356d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3357d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3358d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3359d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3360d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3361d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3362d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3363a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3364a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 33651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3366a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3367a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3368a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 33691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3370a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3371a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3372a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 33731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3374a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 3375a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3376a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 33771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33782140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 33792140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 33802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 33811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 33831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3384a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3385a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 33861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3387a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 3388a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 3389a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 3390a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3391a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3392a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 339356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 33949c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 33954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 339656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 339756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 3398b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 33994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3400b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 34012333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockExprClass, ty, ty->isDependentType(), false), 3402b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 34039c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 340484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 340584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 340684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3407d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 340856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 340984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 341084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 341156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 341256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 341356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 341456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 34159c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 34169c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 341756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 34189c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 34199c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 342056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 342156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 342256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 3423b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 34245b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 3425b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 342684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3427b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 34281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 34299c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 34304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 34314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 34321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 34344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 34354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 34364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 34371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 34394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 34404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 34411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 34424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 34437d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 34447d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 344589f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Stmt *CopyConstructorVal; 34464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 34472333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Fix type/value dependence! 34481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 344989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian bool constAdded = false, 345084ca008a462b515f63871253f494d53c9190363cFariborz Jahanian Stmt *copyConstructorVal = 0) 345184ca008a462b515f63871253f494d53c9190363cFariborz Jahanian : Expr(BlockDeclRefExprClass, t, (!t.isNull() && t->isDependentType()),false), 345252bc56a296b11b4fc6bf5ddf4ded5262f6484bdbFariborz Jahanian D(d), Loc(l), IsByRef(ByRef), 345389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian ConstQualAdded(constAdded), CopyConstructorVal(copyConstructorVal) {} 345494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 345594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 345694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 345794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 345894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 34591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 34614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 346294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 346394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 346494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 346594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 346694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 34674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 34681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 347094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 34711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34727d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 34737d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 347489f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 347589f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian const Expr *getCopyConstructorExpr() const 347689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 347789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Expr *getCopyConstructorExpr() 347889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 347989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; } 348094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 34811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 34821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 34834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 34844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 34851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 34874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 34884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 34894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 34904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 34915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 34925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3494