Expr.h revision f9d68e1dd015972318b2448f75115ff4fc3d5008
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" 21709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 22409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 24525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 253b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 26b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 27c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 30590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 31c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 38409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 41833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 42d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 447ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlssontypedef UsuallyTinyPtrVector<const CXXBaseSpecifier> CXXBaseSpecifierArray; 467ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected: 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// TypeDependent - Whether this expression is type-dependent 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ValueDependent - Whether this expression is value-dependent 60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T, bool TD, bool VD) 64b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(TD), ValueDependent(VD) { 65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 7243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Increases the reference count for this expression. 7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// Invoke the Retain() operation when this expression 7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// is being shared by another owner. 7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Expr *Retain() { 7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Stmt::Retain(); 7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor return this; 7943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor } 801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 90905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 918320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 92f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValueDependent(bool VD) { ValueDependent = VD; } 1070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setTypeDependent(bool TD) { TypeDependent = TD; } 1230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 137026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 138df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 14908ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 15076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 156fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 15786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1582514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 159e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 160e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 16228be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 16353202857c60214d80950a975e6e52aebf30bd16aEli Friedman 16453202857c60214d80950a975e6e52aebf30bd16aEli Friedman // Same as above, but excluding checks for non-object and void types in C 16553202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult isLvalueInternal(ASTContext &Ctx) const; 1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 17244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 17344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 17444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 17544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 180fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 182ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1854f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1865daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 187ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 18886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 1892514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 190e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 191e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 19344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 19444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 19733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 19833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20038d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 20138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 20238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 205093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 206093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2072b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 2082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 2092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 2102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 2112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 2122b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 217590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 218590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 220590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 2218070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 222590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 224c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 225c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 226c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 2302d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 23194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 23494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 23594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 23894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 23994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 24094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 24194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 24294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 24394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 24494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 24594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 24694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 24794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 25094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 25194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2526ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 253019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 254019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 255019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2565b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2575b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 258660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump /// EvaluateAsAny - The same as Evaluate, except that it also succeeds on 259660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump /// stack based objects. 260660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const; 261660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump 262cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 263cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 264cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 265cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 266cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 2676ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 26845b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 26945b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 270c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 2716ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 2726ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// which must be evaluated each time and must not be optimization away 2736ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 2746ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 275393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian bool HasSideEffects(ASTContext &Ctx) const; 276393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian 27751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 27851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 27951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 28051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 281b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 282b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 2831b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 2841b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 285b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it 286b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// also succeeds on stack based, immutable address lvalues. 287b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 288b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman 289ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 290ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 291ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 292ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 293ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 294ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 295ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 296ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 297ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 298ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 299ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 300ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 301ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 302ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 303ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 304efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 305efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 306efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 307ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 308ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 309efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 31044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 312102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3144e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 3164e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 3174e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 3182b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 31956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 32056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 32127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 32256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 325ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 326ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 327ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 3306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 3316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 3326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// by semantic analysis for function calls, object constructions, etc. in 3336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 3346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 3356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 3366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 3376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 3382f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// \brief Determine whether this expression directly creates a 3392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// temporary object (of class type). 3402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor bool isTemporaryObject() const { return getTemporaryObject() != 0; } 3412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 3422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// \brief If this expression directly creates a temporary object of 3432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// class type, return the expression that actually constructs that 3442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor /// temporary object. 3452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor const Expr *getTemporaryObject() const; 3462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 3472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 3484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 3494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 35056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 35156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 35256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 353ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 354ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 355ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 357898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 358898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 359898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 3621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 372a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 373a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 374a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 375a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 376a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 378a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 379a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 380a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 381a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 382a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 383a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 384a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 386a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 387a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 388a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 389a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 390a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 391a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 392a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 393a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 394a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 395a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 396a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 397833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 398833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 399a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 400a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 401a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 402833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 403833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 404a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 405d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 406d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 407d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 408d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 409a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 410a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 414a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 415a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 416a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 417a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 418a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 419a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 420a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 421a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 422a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 423a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // DecoratedD - The declaration that we are referencing, plus two bits to 424a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 425a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // (2) the declaration's name was followed by an explicit template 426a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 427dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 428a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 429a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 4319e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 432a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 433a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 4342cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 435a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 436a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 437a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 438a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 439a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 440a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 441a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 442a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 443a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 444a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 445a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 446a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 447a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 4482cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0) 449a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 450a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4512cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 452a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 453a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 454a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 455a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor getNameQualifier() + 1); 456a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 457a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 458a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 459a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 460a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 461a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList(); 462a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 463a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 464a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 465dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 466d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 4670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T); 468a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4699e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 4700da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 4710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 4720da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 4739e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 474dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) : 4750da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) { 4760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 4770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 4781a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 480dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 4810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) { 4820da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 4830da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4850b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty declaration reference expression. 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit DeclRefExpr(EmptyShell Empty) 4870b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(DeclRefExprClass, Empty) { } 4880b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 491a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 492dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 4940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 4950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 496a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 497dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 498dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 499dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 500904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 5019e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 5020b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 503a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 506a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 507a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 508a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 509a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 512a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 514a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 517a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the nested-name-specifier 520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 524a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determines whether this member expression actually had a C++ 529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 530a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasExplicitTemplateArgumentList() const { 531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag; 532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 533d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 534d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 535d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 536d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 537d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (hasExplicitTemplateArgumentList()) 538d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->copyInto(List); 539d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 540a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 542a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 544a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 545a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 552833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 553a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 555a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 559a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 562a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 563a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 564a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 565a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 566a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 567a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 568a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 570a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 571a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 573a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 574a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 57899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 58377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 58477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 587d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 588d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 589227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 590227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 591227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 592227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 593848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 594848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 595848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 596848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 597227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 599227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 600227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 601227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 602227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 604773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson : Expr(PredefinedExprClass, type, type->isDependentType(), 605773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson type->isDependentType()), Loc(l), Type(IT) {} 6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 60917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 61017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 611227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 61217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 61317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 61417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 61517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 61617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 617848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 6183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 619227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 620227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 623227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 624d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 62777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 62877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 629227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 630227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 6382333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) { 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 641a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 6420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IntegerLiteral(EmptyShell Empty) 6440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 6450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 649313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 650313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 651313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 6520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 6530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 66177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 66277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 668c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 671c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 6722333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l), 6732333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsWide(iswide) { 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6750b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6760b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 6770b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 6780b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 679018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 680c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6860b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6870b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 6880b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 6890b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 69477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 69577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 69677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 69777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 701525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 702720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FloatingLiteral(const llvm::APFloat &V, bool isexact, 706720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 7072333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(FloatingLiteralClass, Type, false, false), Value(V), 7082333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsExact(isexact), Loc(L) {} 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 71017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 71217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 71317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 714c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 71517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setValue(const llvm::APFloat &Val) { Value = Val; } 71617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 717720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 71817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 719c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 720da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 721da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 722da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 723da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 7241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 72617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 72717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 73677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 73777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7405d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 7415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 7425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 7435d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 7445d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 7455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 7465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 7475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 7485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 7492333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {} 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 751cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 753cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 754cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 7565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 757cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 758cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7595d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 7625d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 7635d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7655d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 7665d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 7675d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 7685d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 7695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 770e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 771e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 772e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 773a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 774c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 775c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 776690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 777690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 7788bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 779690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 780c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 781c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 782c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 783c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 784c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 785c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 790726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 791726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 7922085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 7932333f7727f97018d6742e1e0938133bcfad967abEli Friedman StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {} 7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 79642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext &C); 79742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7992085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 8002085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 8012085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 8022085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 803a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 8042085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 8052085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 8061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 8072085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 8082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 8092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 8102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 811a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 812673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 813673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 814673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 815b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 816b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 817b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 818b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar // FIXME: These are deprecated, replace with StringRef. 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 821673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 822673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 823b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 824673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 826673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 827673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 8288d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 829b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 830b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 831b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 83233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 83333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 83433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 835726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 836726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 837726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 839726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 840726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 841726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 842726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 844673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 845673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 846673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 847673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 848b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 849b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 850b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 86177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 86277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 8695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 872898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 874898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 876c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 878c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 879c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 8805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 8815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 882c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 883c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 884866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 886313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 887313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 888c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 889313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 890313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 891313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 892c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 893313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 90077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 90177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 9060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 908dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 909dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 910dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 911dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 912dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 913dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 914dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 91573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subexpression is a compound literal with the various MemberExpr and 91773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 91873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 92113d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 92973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 93073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 9335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 9399103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 9409103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 9411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 9429103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 9460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 9470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 9490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 9500b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 9520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 9530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 9560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 9570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 9592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 9602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 9612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9635a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 9642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 9652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 9662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9675a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 9685a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 9705d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 9725a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isArithmeticOp() const { return isArithmeticOp(Opc); } 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 980bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 981bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 982bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 983bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 984bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 985bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 986bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 987bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 100277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 100377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 10070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 10080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 10090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 10100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1011d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1012a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1013d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1014d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 101642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 101742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 101842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 101942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1021a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 10220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 10230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 10242850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 1025ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 10262850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1027a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TInfo->getType()->isDependentType()), 1028ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1029a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1030ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1031ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1033ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1034ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1035ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 1036ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1037ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1038ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1039ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1040ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1041d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 10420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 10430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 10440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 10450b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 10460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 10480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 10490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 10510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 10525ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 10535ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1054a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 10550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 10565ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 10570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1058caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 10590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1060d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 10610518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1062caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1063caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1064caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 10650b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1067a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1068a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 10700b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 10710b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 10730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 10740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 10750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 10760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 10770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 107876e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 10790b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 10800b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10810b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 10820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1083866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1084866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1085866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1086866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 109477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 109577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 110477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11082324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 110973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 11102850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 11112850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 11122850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 11132850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 111473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 111573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 111673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1118cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1119cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1120cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1121cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11222324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 11232324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 11242324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 11252324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 11262324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 112733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 112833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 112933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 113033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 11315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 11325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1133cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1134cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 11365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1137cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 11405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 114177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 11445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 11452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 11485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11492324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 11525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 115677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1159026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1160cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1161cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11625cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 117077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 117177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 11761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1177b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1179b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1180b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 118277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 11835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1187b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1188b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1189668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1190668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 119142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 119242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11981f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1199ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 12001f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1201668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 12045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 120518b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1206a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1207d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1208d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1209d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1210d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1211d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1212a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1213a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1214bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1215bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1216bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1217a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 12255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 12295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1232934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1233934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1234934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1235934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1236934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1238d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1239d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1240d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 12418189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 12445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1246d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1247d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 12485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 12495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1256cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 12573c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 12616dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 12626dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1264d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 12651f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1266866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 126877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1272b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 127388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() == CXXMemberCallExprClass; 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 127788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 127888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 127988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 128077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 128177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 128277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1285ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 12886bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 12896bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1290161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 12916bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 12926bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1293ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1294ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 12955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1297ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1298ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1299f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1301ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1304ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 130583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 13086bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 13096bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1310c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 13116bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 13121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1313c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1314c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1315c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1316c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 13176bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1318c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 13216bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 13226bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 13236bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 132483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 132583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 132683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 13276bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1328c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1329c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1331c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1332c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1333c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1334c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 133583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13376bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1338c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1340c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 1341c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor getMemberQualifier() + 1); 1342c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1344c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1345c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1346c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1347c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList(); 134883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1351f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1352f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceLocation l, QualType ty) 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 1354ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 135583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 13566bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1357510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 13581f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty member reference expression. 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit MemberExpr(EmptyShell Empty) 13606bb8017bb9e828d118e15e59d71c66bba323c364John McCall : Expr(MemberExprClass, Empty), HasQualifierOrFoundDecl(false), 1361e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor HasExplicitTemplateArgumentList(false) { } 13621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 136483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 1365161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 1366c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation l, 1367d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1368c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty); 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 137088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 13715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 137257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 137357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 137457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 137557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 137657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1377f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1378f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 13791f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13806bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1381161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 13826bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1383161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1384161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 13856bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 13866bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 13876bb8017bb9e828d118e15e59d71c66bba323c364John McCall 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 13890979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 13900979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 13916bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 139483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 139583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 13976bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 139883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 140083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 140183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 140483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 140583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 14076bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 140883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 141183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1412c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1413c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1414c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1415d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall bool hasExplicitTemplateArgumentList() const { 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1417c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1419d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1420d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1421d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1422d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (hasExplicitTemplateArgumentList()) 1423d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->copyInto(List); 1424d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 1425d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1427c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 14281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1429c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1430c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1432c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 1433c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1435c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1436c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 1437833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1438c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1441c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 1442c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1444c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1445c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1447c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1450c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 1451c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1454c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1456c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1457c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1459c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 1460c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 14631f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 14641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1465ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1466ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1467026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 14681f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 147172527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 147272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 1473c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation EndLoc = MemberLoc; 1474c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (HasExplicitTemplateArgumentList) 1475c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor EndLoc = getRAngleLoc(); 14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 147872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1479c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1480c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 148683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14901237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14911237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14921237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1496aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1497aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 14980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 14990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 15000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 15010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 15021d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 15031d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 15041d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 150542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 15065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1507e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1508aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 15092333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can compound literals be value-dependent? 151042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 15111d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall QualType T, Expr *init, bool fileScope) 15121d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall : Expr(CompoundLiteralExprClass, T, 151342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall tinfo->getType()->isDependentType(), false), 151442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1516ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1517ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1518ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1519ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 15205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 15215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1522ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1523e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1524e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1525ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1526ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 15270fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1528ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1529ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 153042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 153142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 153242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 153373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 15340fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 15350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 15360fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 15370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 153873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 15390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 154073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1541aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1544aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1545aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15471237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15481237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15491237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1550aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1551aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 155249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 155349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 155449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 155549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 15560835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 1557cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 1558cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CastKind - the kind of cast this represents. 1559cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson enum CastKind { 1560cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_Unknown - Unknown cast kind. 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// FIXME: The goal is to get rid of this and make all casts have a 1562cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// kind so that the AST client doesn't have to try to figure out what's 1563cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// going on. 1564cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_Unknown, 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1566cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_BitCast - Used for reinterpret_cast. 1567cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_BitCast, 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1569cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_NoOp - Used for const_cast. 15703503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson CK_NoOp, 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157211de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson /// CK_BaseToDerived - Base to derived class casts. 157311de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson CK_BaseToDerived, 157411de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson 15753503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson /// CK_DerivedToBase - Derived to base class casts. 1576714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson CK_DerivedToBase, 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157823cba801e11b03929c44f8cf54578305963a3476John McCall /// CK_UncheckedDerivedToBase - Derived to base class casts that 157923cba801e11b03929c44f8cf54578305963a3476John McCall /// assume that the derived pointer is not null. 158023cba801e11b03929c44f8cf54578305963a3476John McCall CK_UncheckedDerivedToBase, 158123cba801e11b03929c44f8cf54578305963a3476John McCall 1582714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson /// CK_Dynamic - Dynamic cast. 15834d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson CK_Dynamic, 15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15854d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson /// CK_ToUnion - Cast to union (GCC extension). 1586112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson CK_ToUnion, 15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1588112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson /// CK_ArrayToPointerDecay - Array to pointer decay. 158927a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_ArrayToPointerDecay, 15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1591b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson // CK_FunctionToPointerDecay - Function to pointer decay. 1592b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson CK_FunctionToPointerDecay, 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 159427a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_NullToMemberPointer - Null pointer to member pointer. 159527a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_NullToMemberPointer, 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 159727a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 159827a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// member pointer in derived class. 15999099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian CK_BaseToDerivedMemberPointer, 16009099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian 16011a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 16021a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson /// member pointer in base class. 16031a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson CK_DerivedToBaseMemberPointer, 16041a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// CK_UserDefinedConversion - Conversion using a user defined type 160658d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian /// conversion function. 16077fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian CK_UserDefinedConversion, 16087fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian 16097fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian /// CK_ConstructorConversion - Conversion by constructor 16107f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_ConstructorConversion, 16117f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 16127f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_IntegralToPointer - Integral to pointer 16137f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_IntegralToPointer, 16147f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 16157f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_PointerToIntegral - Pointer to integral 1616ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson CK_PointerToIntegral, 1617ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson 1618ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson /// CK_ToVoid - Cast to void. 161916a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson CK_ToVoid, 162016a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson 162116a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// CK_VectorSplat - Casting from an integer/floating type to an extended 162216a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// vector type with the same element type as the src type. Splats the 1623f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson /// src expression into the destination expression. 162482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_VectorSplat, 162582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 162682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralCast - Casting between integral types of different size. 162782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralCast, 162882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 162982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralToFloating - Integral to floating point. 163082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralToFloating, 163182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 163282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingToIntegral - Floating point to integral. 163382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_FloatingToIntegral, 163482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 163582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingCast - Casting between floating types of different size. 1636bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson CK_FloatingCast, 1637bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson 1638bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson /// CK_MemberPointerToBoolean - Member pointer to boolean 163992ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian CK_MemberPointerToBoolean, 164092ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian 164192ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c 164292ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian /// pointer 16433b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian CK_AnyPointerToObjCPointerCast, 16443b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block 16453b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian /// pointer 16463b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian CK_AnyPointerToBlockPointerCast 1647bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson 1648cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson }; 16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1650cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 1651cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind Kind; 16520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 1653409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 16547ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson /// BasePath - For derived-to-base and base-to-derived casts, the base array 16557ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson /// contains the inheritance path. 1656f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson CXXBaseSpecifierArray BasePath; 16577ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 16587ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson void CheckBasePath() const { 1659409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 1660409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 16615cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 1662cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 1663cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 1664409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 1665409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 1666f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson assert(!BasePath.empty() && "Cast kind should have a base path!"); 1667f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 1668409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 1669409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 1670409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Unknown: 1671409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 1672409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NoOp: 1673409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 1674409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 1675409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 1676409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 1677409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 1678409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_UserDefinedConversion: 1679409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 1680409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 1681409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 1682409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 1683409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 1684409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 1685409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 1686409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 1687409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 1688409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_MemberPointerToBoolean: 1689409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 1690409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 16915cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson assert(BasePath.empty() && "Cast kind should not have a base path!"); 1692409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 1693409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 1694409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 1695409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 1696409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 16970835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 1698409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op, 1699f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson CXXBaseSpecifierArray BasePath) : 1700898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1701898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1702898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1703898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1704898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1705898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 17077ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson Kind(kind), Op(op), BasePath(BasePath) { 17087ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson CheckBasePath(); 1709409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1711087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CastExpr(StmtClass SC, EmptyShell Empty) 1713087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : Expr(SC, Empty) { } 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1715a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson virtual void DoDestroy(ASTContext &C); 1716a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson 17170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 1718cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind getCastKind() const { return Kind; } 1719cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson void setCastKind(CastKind K) { Kind = K; } 1720f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 1721f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 17220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 17230835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 1724087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 1725087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 17266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 17276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 17286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 17296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 17306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 17316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 17326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 173341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 173441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson const CXXBaseSpecifierArray& getBasePath() { return BasePath; } 173541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17379d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 1738d8383d45e41ba2316610e5d638d2872e37b67cfbZhongxing Xu if (SC >= CXXStaticCastExprClass && SC <= CXXFunctionalCastExprClass) 17399d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 17409d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 17416eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 17420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 17439d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 17449d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 17450835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 17460835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17480835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 17490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 17500835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 17510835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 17520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 175349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 175449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 175549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 175649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 175749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1758bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1759bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1760bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1761bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1762bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1763bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1764bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 1766bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1767bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1768bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 17690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1770eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1771eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1772eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 177349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 177488465d3e996e627bbaa11099b039ddab66d5af2cAnders Carlsson ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 1775f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson CXXBaseSpecifierArray BasePath, bool Lvalue) 17767ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath), 17777ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson LvalueCast(Lvalue) { } 177890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1779087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitCastExpr(EmptyShell Shell) 1781087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : CastExpr(ImplicitCastExprClass, Shell) { } 1782087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 17830835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 17840835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 17850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 178690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1787eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1788eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1789eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1790eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1791eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1792eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 17931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 179549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 179649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 179749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 179849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 179949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 180149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 180249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 180349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 180449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 180549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 180649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 18075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 180849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 180949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 181049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 181149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 181249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 181349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 181449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 18150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 18169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 18179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 18189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 181949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 182049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 1821c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 182241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson Expr *op, CXXBaseSpecifierArray BasePath, 182341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson TypeSourceInfo *writtenTy) 182441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson : CastExpr(SC, exprTy, kind, op, BasePath), TInfo(writtenTy) {} 182549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 1826db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExplicitCastExpr(StmtClass SC, EmptyShell Shell) 1828db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : CastExpr(SC, Shell) { } 1829db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 183049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 18319d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 18329d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 18339d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 18349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 18359d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 183649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 183749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 18389d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 183949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18419d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 184209cc141c89a5e9f305c17d7a88298647df16ceddJohn McCall if (SC >= CStyleCastExprClass && SC <= CStyleCastExprClass) 18439d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 1844d8383d45e41ba2316610e5d638d2872e37b67cfbZhongxing Xu if (SC >= CXXStaticCastExprClass && SC <= CXXFunctionalCastExprClass) 184549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 18469d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 18479d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 184849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 184949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 185049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 185149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 18526eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 185349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 185449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 18556eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1856b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1857b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18599d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, 186041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy, 186141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 186241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, BasePath, 186341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 186449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1865db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CStyleCastExpr(EmptyShell Shell) 1867db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : ExplicitCastExpr(CStyleCastExprClass, Shell) { } 1868db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1869b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1870db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 1871db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1872b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 1873db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 1874db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1876b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18816eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 18853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 18863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 18873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 18883fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 18893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 18903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 18913fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 18923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 18933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 18943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 18953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 18963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 18973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 18983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 18993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 19003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 19013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 19055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 190603d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1907224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 19105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 19115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 19125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 19135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 19225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 19235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 192617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 192717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 19285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 192917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 193017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 193317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 193417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1935898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1936898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 1938898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 19391237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 19401237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1945db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 1947db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 1948db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 194917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 1950db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 1951db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 19525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 1953db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 1954db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 19555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1956db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 19575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1958db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 1959db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 19605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 19615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 19625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 19655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 19675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1968063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1969063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1970063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1971063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1972063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1973063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1974063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1975063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 197940a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; } 198040a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek bool isShiftOp() const { return isShiftOp(Opc); } 1981aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 1982aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; } 1983aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isBitwiseOp() const { return isBitwiseOp(Opc); } 1984f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1985f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1986f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1987f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1989f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1991aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; } 1992aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isComparisonOp() const { return isComparisonOp(Opc); } 1993aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 1994f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1995f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1996f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 2002eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump S->getStmtClass() == CompoundAssignOperatorClass; 20045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 20061237c673c07f9d827129ba02720108816abde562Ted Kremenek 20071237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20081237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20091237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 20101237c673c07f9d827129ba02720108816abde562Ted Kremenek 20115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 201217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 20132333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 20142333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CompoundAssignOperatorClass, ResTy, 20152333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 20162333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isValueDependent() || rhs->isValueDependent()), 20172333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 20181237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 20191237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 20205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2021ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 2023ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(SC, Empty), Opc(MulAssign) { } 20245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 20275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 20285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 20295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 20305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 20315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2033ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2034ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 20355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 2037ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 2038ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 203917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 204017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 2041ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2042ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 20445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 20455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2047ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2048ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2049ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2050ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2051ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2052ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2053ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2054ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2055ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2056ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2057ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2058ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2059ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 20635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 20675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 20685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 20701237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 20715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 207247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 20735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 207447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 207547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation CLoc, Expr *rhs, QualType t) 2076898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 2077898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2078898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2079898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 2080898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 2082898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 208347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 208447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 208547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 20861237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 20871237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 20881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 20891237c673c07f9d827129ba02720108816abde562Ted Kremenek } 20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2091ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2092ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 2093ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 2094ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2095395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 2096395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 20975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2098ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 2099395a2abf0028968d85958610e393e067885dc14fTed Kremenek 2100395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2101395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 2102395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 2103395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 2104395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 21051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // is only evaluated once. 2106395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 21075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 2108395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 21091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2110395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2111395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 21125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 2115ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2116ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 21175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2118ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 212047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 212147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 212247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 212347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 212447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 212547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 21265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 21275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 21285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 21331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21341237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 21351237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 21361237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 21375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21396481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 21406481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 21425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 21435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 21446481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 21456481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 21462333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(AddrLabelExprClass, t, false, false), 21472333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 21517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 21527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 21537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 21547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 21557d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 21567d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 21577d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 21585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 21595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 21605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 21637d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 21647d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 21655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 21675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21686481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 21691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21701237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 21711237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 21721237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 21735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2174ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2175ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2176ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2177ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2178ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 21795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2180ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2181ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 21822333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2183d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2184d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 21852333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(StmtExprClass, T, T->isDependentType(), false), 21862333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21886a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 21896a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 21906a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 21915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 21925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 21936a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 21946a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2195ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2196ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2197ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2199026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 22006a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2201026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 22026a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2204ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 22051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2206ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2207ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22091237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 22101237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 22111237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2212ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2213ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2214dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2215d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2216d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2217d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2218d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 2219d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 2220d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 2221363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2222d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 22241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType t1, QualType t2, SourceLocation RP) : 22252333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(TypesCompatibleExprClass, ReturnType, false, false), 22262333f7727f97018d6742e1e0938133bcfad967abEli Friedman Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2227d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 222844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 222944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 223044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 223144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 22327f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 223344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType1(QualType T) { Type1 = T; } 22347f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 223544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType2(QualType T) { Type2 = T; } 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 223844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 224044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 224144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 22421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2243d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2244363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2245d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2246d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 22471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2248d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2249d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 22501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22511237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 22521237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 22531237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2254d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2255d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2256d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2257d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2258d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2259d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2260d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2261d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2262d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2263d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2264d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2265d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2266d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2267d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2268d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 22695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2270d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2271d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2272888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected: 22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 2274888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2275d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 22762333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 22772333f7727f97018d6742e1e0938133bcfad967abEli Friedman // to be computed differently? 2278a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 22812333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false), 22822333f7727f97018d6742e1e0938133bcfad967abEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2284a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2285d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2286d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2287d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 228894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 228994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 22901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 229194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 229294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 229394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 229494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 229694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 229794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 229894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2299d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2300d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2301d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2302d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2304d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2305d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2307888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman ~ShuffleVectorExpr() {} 23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2309d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2310d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2311d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2312d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 23131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2314d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2315d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2316d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 23175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2318d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2319d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2320d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 23215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2322d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2324888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 232594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2326dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2327dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 23289a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2329d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2331d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2332d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2333d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2334d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2335d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2336d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2338d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 23397976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 23407976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 23417976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 23427976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 23437976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 23447976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2345d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 23461237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 23475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2348d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2349d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2350d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2351ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2352ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 23531237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 23541237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 23551237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 23561237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 23571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 23587976932a1c256d447316ffac58e9821417725e34Eli Friedman 235944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 236044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 236144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 23627976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 23637976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 236427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 23657976932a1c256d447316ffac58e9821417725e34Eli Friedman 23667976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 23677976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 23687976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 23697976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 23707976932a1c256d447316ffac58e9821417725e34Eli Friedman } 23717976932a1c256d447316ffac58e9821417725e34Eli Friedman 23725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 237344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 23745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 237544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 23765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 237744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 237844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 237944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 238044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 23811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 238244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 238344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 23841237c673c07f9d827129ba02720108816abde562Ted Kremenek 2385d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2386d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2387d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2388d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2390d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2391d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23931237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 23941237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 23951237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2396d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2397d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 23982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 23992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 24002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 24012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 24022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 24032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 24042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 24052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 24062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 24072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 24082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 24091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 24102333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { } 24112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 241244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 241344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 241444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 24152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 24162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 241744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 24182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 24192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 24202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 24212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 24222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 24242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 24252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 24261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 24282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 24292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 24302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 24312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 243274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 24337c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 24345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 24357c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 24367c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 24377c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 24382333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(VAArgExprClass, t, t->isDependentType(), false), 24397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 24407c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 24417c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244374626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 2444d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2445d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 24465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 24475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2448d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2449d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2450d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2451d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2453d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2454d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2455d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 24567c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 24577c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24597c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 24607c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 24617c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 24627c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 24631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 24657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 24677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 24704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 24714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 24724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 24734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 24744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 24754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 24764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 24774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2478196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 24794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 24804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 24814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 24824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 24834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 24844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 24854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 24864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2487196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 24884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 24894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 24904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 24914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 24924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 24934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 24944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 24953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 24964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 24974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 24984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2499196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 25004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 25014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 25024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 25034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 25044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 25054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 250666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 2507ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 2508709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 2509709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 251066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 25111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 25134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 25144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 25154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 25160bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 25170bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 25180bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 25190bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2520a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2521a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2522a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2523a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 252466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 2525709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 2526709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 2527ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 2528d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2529d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2530709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 2531709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 25321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2533ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 25341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getInit(unsigned Init) const { 2536c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 25374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 253866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 25391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getInit(unsigned Init) { 2541c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 25424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 254366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 25441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2546c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 25479e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 25489e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2549c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2550fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2551709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 25544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 25554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 25564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 25574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 25584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 25594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 25604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 25614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 25624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 25634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 25644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 25654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 25664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 25674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 2568709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 2569c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 25700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 25710bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 25720bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 25730bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 25740bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 25750bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 25760bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 25770bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 25780bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2579c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2580c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2581b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2582b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2583b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 25841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2585d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2586d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2587d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 258887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 258987fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 25904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 25914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 25924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 25931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 25944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 25954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 25964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2597a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 25981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 2599d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 2600a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 2601a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 260266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 260366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 26041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 260566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 260766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 260866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 261066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 261166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 261266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 26131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2614709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 2615709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2617ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 2618ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 2619ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 2620ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 262166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 262266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 262305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 262405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 262505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 262605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 262705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 262805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 262905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 26301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 263105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 263205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 263305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 263405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 263505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 263605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 263705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 263805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 263905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 264005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 264105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 264205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 264305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 2644ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 2645ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 2646ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 2647ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2648ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 264905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 265005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 265105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 265205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2653eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 265405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 2655eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 265605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 265705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 265805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 265905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2660ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 2661ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 2662ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 2663ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 266405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 266505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 266605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 266705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 266805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2669ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2670319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 2671ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 2672eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 26739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 26749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 267505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2676d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 2677d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 2678d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 2679d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 268042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 26811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 268242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 2683319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void DestroyDesignators(ASTContext &C); 2684319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor 268505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 268605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 268705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 268805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 268905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 269005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 269105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 269205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 269305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 269405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 269605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 269705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 269905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 270005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 270105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 270205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 270305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 270405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 270505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 270605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 270705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 270805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 270905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 271005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 271105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 271205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 271305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 271505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 271605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 271705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 271805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 271905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 272005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 272105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 272205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 272305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 272405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 272505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 272605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 272705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 272805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 272905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 273005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 273105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 273205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 273305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 273405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 273505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 273605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 273705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 273805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 273905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 2740ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 2741ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 274205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 27431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 27441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 274505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 274605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 274705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 274805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 274905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 275005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 275105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 275305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 275405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 275505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 275605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 275705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 275805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 275905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 276005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 276105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 276305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 276405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 276505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 276605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 276705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 276805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 276905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 277005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 277105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 277205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 277305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 277405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 277505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 277605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 277705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 277805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 277905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 278005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 278105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 278205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 278305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 278405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 278505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 278605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 278705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 278805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 278905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 279087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 279187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 279287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 279387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 279487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 279505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 279605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 279705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 279805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 279905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 280005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 280105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 280205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 280305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 280405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 280505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 280605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 280705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 280805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 280905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 281005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 281105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 281205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 281305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 281405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 281505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 281605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 28174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2818d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 2819d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 2820d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 2821d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 2822d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2823d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 28244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 28254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 28264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 28274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 28284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 28294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 283005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 283105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 28321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 283305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 283405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 283505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 2836eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 283705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2838d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 2839d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 284005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 284105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 284205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 284305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 284405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 2845ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 28461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 2848ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 284905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2850711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 2851711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 2852319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void setDesignators(ASTContext &C, const Designator *Desigs, 2853319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 2854d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 285505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 285605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 285705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 285805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 285905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 286005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 286105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 2862d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 286305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 286405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 2865eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 2866eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 2867d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 286805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 286905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 287105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 287205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 287305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 287405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 287505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 287605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 287705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2878d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 2879d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 2880d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 2881d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 2882d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 2883d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2884d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 2885d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2886d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2887d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2888d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 2889d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2890d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2891d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 2892d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2893d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2894d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2895d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 2896d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2897d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2898ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 2899ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 2900319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 2901ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 2902ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 290305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 290405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 290505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 29061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 290705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 290805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 290905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 291005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 291105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 29121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 29133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 29143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 29153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 29163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 29173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 29181a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 29191a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 29203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 29211a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 29221a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 29243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 29251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 29262333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImplicitValueInitExprClass, ty, false, false) { } 29273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 2928d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 2929d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 2930d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 2931d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 29343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 29353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 29363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 29373498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 29383498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 29393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 29403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 29413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 29423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 29431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 294405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 294505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 29462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 29482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 29492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 29502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 29512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected: 29532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual void DoDestroy(ASTContext& C); 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 29572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 29582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman ~ParenListExpr() {} 29602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 29622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 29631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 29651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 29672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 29682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 29692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 29701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 29722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 29732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 29742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 29752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 297683ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 29771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 29792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 29802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 29822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 29842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 29851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 29862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 29872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 29881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 29902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 29912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 29922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 29932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 29964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 29974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 29984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2999a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3000a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3001a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3002a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3003a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 300473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 300573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 300673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3007a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3008a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3009d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3010a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3011a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3012a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 3013a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 30142333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(), 30152333f7727f97018d6742e1e0938133bcfad967abEli Friedman base->isValueDependent()), 3016d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 30171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3018d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3019d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3020d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3021d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3022a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3023a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3024d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3025d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3026d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3027d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3028d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3029d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3030d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3031d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3032a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3033a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 30341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3035a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3036a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3037a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3039a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3040a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3041a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 30421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3043a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 3044a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3045a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 30461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30472140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 30482140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 30492140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 30501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3053a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3054a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 30551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3056a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 3057a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 3058a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 3059a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3060a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3061a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 306256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 30639c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 30644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 306556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 306656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 3067b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 30684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3069b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 30702333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockExprClass, ty, ty->isDependentType(), false), 3071b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 30729c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 307384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 307484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 307584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3076d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 307756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 307884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 307984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 308056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 308156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 308256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 308356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 30849c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 30859c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 308656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 30879c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 30889c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 308956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 309056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 309156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 3092b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 30935b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 3094b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 309584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3096b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30989c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 30994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 31004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 31011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 31034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 31044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 31054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 31061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 31084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 31094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 31114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 31127d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 31137d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 31144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 31152333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Fix type/value dependence! 31161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 31172333f7727f97018d6742e1e0938133bcfad967abEli Friedman bool constAdded = false) 31182333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef), 31192333f7727f97018d6742e1e0938133bcfad967abEli Friedman ConstQualAdded(constAdded) {} 312094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 312194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 312294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 312394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 312494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 31274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 312894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 312994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 313094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 313194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 313294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 31334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 31341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 313694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 31371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31387d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 31397d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 314094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 31421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 31434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 31444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 31474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 31484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 31494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 31504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 31515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 31525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 31535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3154