Expr.h revision e9ff443040cb571ae2c5c2626c4dc9a9a812d84a
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" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 21525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 223b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 23b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 24c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 27590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 28c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 29c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 31c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 328e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 3588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 3688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 37833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 38d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 46898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected: 481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// TypeDependent - Whether this expression is type-dependent 49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 50898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ValueDependent - Whether this expression is value-dependent 53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T, bool TD, bool VD) 57b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(TD), ValueDependent(VD) { 58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 59898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 620b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 6543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Increases the reference count for this expression. 6643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 6743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// Invoke the Retain() operation when this expression 6843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// is being shared by another owner. 6943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Expr *Retain() { 7043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Stmt::Retain(); 7143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor return this; 7243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor } 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 74f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 83905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 848320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 85f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValueDependent(bool VD) { ValueDependent = VD; } 1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setTypeDependent(bool TD) { TypeDependent = TD; } 1160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 128026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 129026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 130026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 131df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 14208ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 14376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 149fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 15086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1512514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 152e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 153e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertyGetterSetting 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 15528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 15653202857c60214d80950a975e6e52aebf30bd16aEli Friedman 15753202857c60214d80950a975e6e52aebf30bd16aEli Friedman // Same as above, but excluding checks for non-object and void types in C 15853202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult isLvalueInternal(ASTContext &Ctx) const; 1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 16544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 16644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 16744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 16844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 173fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 175ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1784f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1795daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 180ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 18186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 1822514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 183e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 184e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertyGetterSetting 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 18644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 18744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 19033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 19133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 19438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 19538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 198093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 199093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 204590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 205590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 207590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 2088070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 209590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 211c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 212c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 213c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 2172d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 21894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 22194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 22294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 22594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 22694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 22794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 22894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 23094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 23194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 23294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 23394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 23494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 23794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 23894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2396ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 240019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 241019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 242019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2435b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2445b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 245660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump /// EvaluateAsAny - The same as Evaluate, except that it also succeeds on 246660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump /// stack based objects. 247660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const; 248660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump 249cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 250cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 251cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 252cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 253cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 2546ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 25545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 25645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 257c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 2586ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 2596ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// which must be evaluated each time and must not be optimization away 2606ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 2616ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 262393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian bool HasSideEffects(ASTContext &Ctx) const; 263393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian 26451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 26551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 26651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 26751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 268b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 269b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 2701b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 2711b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 272b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it 273b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// also succeeds on stack based, immutable address lvalues. 274b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 275b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman 276ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 277ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 278ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 279ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 280ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 281ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 282ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 283ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 284ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 285ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 286ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 287ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 288ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 289ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 290ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 291efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 292efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 293efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 294ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 295ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 296efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 29744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 299102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3014e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 3034e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 3044e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 3054e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* IgnoreParens(); 30656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 30756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 30827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 30956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 311ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 312ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 313ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 314ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 3176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 3186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 3196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// by semantic analysis for function calls, object constructions, etc. in 3206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 3216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 3226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 3236eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 3246eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 3254e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek const Expr* IgnoreParens() const { 3264e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 3274e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 32856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 32956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 33056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 331ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 332ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 333ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 335898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 336898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 337898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 3401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 350a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 351a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 352a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 353a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 354a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 355a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 356a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 357a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 358a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 359a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 360a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 361a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 362a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 363a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 364a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 365a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 366a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 367a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 368a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 369a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 370a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 371a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 372a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 373a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 374a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 375833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 376833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 378a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 379a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 380833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 381833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 382a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 383d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 384d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 385d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 386d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 387a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 388a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 392a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 393a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 394a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 395a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 396a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 397a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 398a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 399a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 400a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 401a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // DecoratedD - The declaration that we are referencing, plus two bits to 402a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 403a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // (2) the declaration's name was followed by an explicit template 404a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 405dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 406a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 407a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 4099e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 410a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 411a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 4122cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 413a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 414a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 415a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 416a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 417a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 418a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 419a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 420a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 421a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 422a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 423a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 424a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 425a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 4262cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0) 427a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 428a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4292cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 431a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 432a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 433a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor getNameQualifier() + 1); 434a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 435a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 436a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 437a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 438a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 439a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList(); 440a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 441a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 442a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 443dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 444d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 4450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T); 446a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4479e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 4480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 4490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 4500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 4519e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 452dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) : 4530da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) { 4540da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 4550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 4561a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 458dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 4590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) { 4600da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 4610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty declaration reference expression. 4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit DeclRefExpr(EmptyShell Empty) 4650b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(DeclRefExprClass, Empty) { } 4660b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 467a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 468a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 469a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 470dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 471a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 4720da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 4730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 475dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 476dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 477dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 478904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 4799e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 4800b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 485a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 488a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 491a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 492a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 495a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 496a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the nested-name-specifier 498a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 499a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 500a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 501a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 503a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 504a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 506a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determines whether this member expression actually had a C++ 507a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 508a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasExplicitTemplateArgumentList() const { 509a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag; 510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 511d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 512d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 513d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 514d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 515d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (hasExplicitTemplateArgumentList()) 516d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->copyInto(List); 517d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 524a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 530833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 533a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 534a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 536a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 537a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 540a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 542a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 544a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 545a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 553a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 55699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 56177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 56277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 565d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 566d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 567227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 568227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 569227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 570227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 571cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor PrettyFunction 572227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 574227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 575227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 576227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 577227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 579773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson : Expr(PredefinedExprClass, type, type->isDependentType(), 580773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson type->isDependentType()), Loc(l), Type(IT) {} 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 58417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 58517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 586227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 58717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 58817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 58917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 59017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 59117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 5923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson static std::string ComputeName(ASTContext &Context, IdentType IT, 5933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const Decl *CurrentDecl); 5943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 595227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 596227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 5971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 599227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 600d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 6011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 60377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 60477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 605227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 606227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 6142333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) { 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 617a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 6180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IntegerLiteral(EmptyShell Empty) 6200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 6210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 625313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 626313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 627313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 6280b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 6290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 63777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 63877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 644c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 647c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 6482333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l), 6492333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsWide(iswide) { 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 6530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 6540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 655018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 656c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6620b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 6640b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 6650b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 67077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 67177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 67277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 67377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 677525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 678720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FloatingLiteral(const llvm::APFloat &V, bool isexact, 682720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 6832333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(FloatingLiteralClass, Type, false, false), Value(V), 6842333f7727f97018d6742e1e0938133bcfad967abEli Friedman IsExact(isexact), Loc(L) {} 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 68617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 68817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 68917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 690c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 69117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setValue(const llvm::APFloat &Val) { Value = Val; } 69217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 693720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 69417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 695c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 696da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 697da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 698da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 699da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 70217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 70317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 71277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 71377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 7175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 7185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 7195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 7205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 7215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 7225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 7235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 7245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 7252333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {} 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 727cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 729cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 730cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 7325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 733cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 734cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7355d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 7385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 7395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 7425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 7435d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 7445d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 7455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 746e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 747e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 748e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 749a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 750c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 751c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 752690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 753690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 7548bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 755690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 756c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 757c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 758c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 759c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 760c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 761c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 766726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 767726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 7682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 7692333f7727f97018d6742e1e0938133bcfad967abEli Friedman StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {} 7701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 77242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext &C); 77342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 7762085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 7772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 7782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 779a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 7802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 7812085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 7832085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 7842085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 7852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 7862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 787a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 788673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 789673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 790673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 791b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 792b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 793b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 794b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar // FIXME: These are deprecated, replace with StringRef. 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 797673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 798673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 799b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 800673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 802673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 803673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 8048d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 805b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 806b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 807b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 80833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 80933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 81033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 811726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 812726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 813726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 815726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 816726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 817726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 818726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 820673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 821673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 822673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 823673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 824b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 825b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 826b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 83777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 83877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 8455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 848898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 850898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 852c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 854c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 855c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 8565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 8575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 858c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 859c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 860866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 862313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 863313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 864c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 865313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 866313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 867313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 868c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 869313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 87677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 87777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 8820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 884dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 885dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 886dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 887dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 888dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 889dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 890dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 89173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subexpression is a compound literal with the various MemberExpr and 89373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 89473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 89713d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 90573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 90673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 9095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 9159103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 9169103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 9171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 9189103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 9220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 9230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 9250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 9260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 9280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 9290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 9320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 9330b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 9352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 9362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 9372085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9395a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 9402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 9412085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 9422085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9435a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 9445a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 9465d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 9485a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isArithmeticOp() const { return isArithmeticOp(Opc); } 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 956bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 957bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 958bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 959bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 960bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 961bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 962bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 963bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 97877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 97977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 9830518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 9840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 9850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 9860518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 987d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 988a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 989d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 990d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 99242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 99342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 99442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 99542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 997a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 9980518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 9990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 10002850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 1001ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 10022850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1003a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TInfo->getType()->isDependentType()), 1004ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1005a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1006ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1007ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1009ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1010ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1011ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 1012ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1013ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1014ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1015ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1016ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1017d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 10180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 10190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 10200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 10210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 10220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 10240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 10250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 10270518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 10285ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 10295ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1030a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 10310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 10325ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 10330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1034caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 10350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1036d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 10370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1038caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1039caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1040caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 10410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1043a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1044a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 10460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 10470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 10490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 10500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 10510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 10520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 10530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 105476e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 10550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 10560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 10580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1059866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1060866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1061866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1062866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 107077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 107177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 108077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10842324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 108573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 10862850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 10872850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 10882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 10892850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 109073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 109173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 109273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1094cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1095cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1096cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1097cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 10982324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 10992324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 11002324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 11012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 11022324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 110333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 110433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 110533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 110633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 11075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 11085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1109cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1110cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 11125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1113cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 11165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 111777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 11181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 11205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 11212324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 11245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11252324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 11285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 113277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1136cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1137cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11385cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 114677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 114777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1151b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1153b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1155b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1156b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 115877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 11595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1164b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1165668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1166668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 116742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 116842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 11731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11741f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1175ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 11761f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1177668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 11805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 118118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1182a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1183d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1184d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1185d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1186d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1187d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1188a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1189a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1190bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1191bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1192bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1193a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 12015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 12055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1208934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1209934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1210934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1211934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1212934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1214d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1215d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1216d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 12178189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 12205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1222d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1223d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 12245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 12255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1231cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1232cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 12333c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 12376dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 12386dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1240d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 12411f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1242866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 124477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1248b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 124988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() == CXXMemberCallExprClass; 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 125388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 125488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 125588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 125677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 125777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 125877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1261ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 1264ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1265ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 12665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1268ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1269ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1270f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1272ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1275ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 127683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// refer to the member, e.g., "x->Base::f". When true, a NameQualifier 1280c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 128183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool HasQualifier : 1; 12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1283c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1284c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1285c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1286c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 1287c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the NameQualifier structure. 1288c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 129183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NameQualifier *getMemberQualifier() { 129283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 129383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 129683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 129783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 129883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 129983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor const NameQualifier *getMemberQualifier() const { 1300c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1301c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1303c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1304c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1305c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1306c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 130783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1309c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasQualifier) 1310c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1312c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 1313c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor getMemberQualifier() + 1); 1314c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1316c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1317c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1318c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1319c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList(); 132083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual, 1323f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceRange qualrange, ValueDecl *memberdecl, SourceLocation l, 1324d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, QualType ty); 132583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1327f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1328f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceLocation l, QualType ty) 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 1330ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 133183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 1332c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor HasQualifier(false), HasExplicitTemplateArgumentList(false) {} 1333510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 13341f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty member reference expression. 13351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit MemberExpr(EmptyShell Empty) 13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, Empty), HasQualifier(false), 1337e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor HasExplicitTemplateArgumentList(false) { } 13381f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 134083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 1341f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 1342c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation l, 1343d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1344c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty); 13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 13475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 134857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 134957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 135057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 135157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 135257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1353f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1354f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 13551f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 13570979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 13580979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 135983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool hasQualifier() const { return HasQualifier; } 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 136283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 136383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 136583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 136683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 136983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 137283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 137383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 137583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 137683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 137883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 137983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1380c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1381c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1382c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1383d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall bool hasExplicitTemplateArgumentList() const { 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1385c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1387d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1388d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1389d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1390d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (hasExplicitTemplateArgumentList()) 1391d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->copyInto(List); 1392d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 1393d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1395c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1397c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1398c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1400c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 1401c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1403c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1404c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 1405833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1406c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 14071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1409c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 1410c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1412c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1413c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1415c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1418c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 1419c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1422c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 14231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1424c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1425c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1427c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 1428c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 14311f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 14321f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1433ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1434ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1435026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 14361f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 143972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 144072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 1441c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation EndLoc = MemberLoc; 1442c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (HasExplicitTemplateArgumentList) 1443c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor EndLoc = getRAngleLoc(); 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 144672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1447c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1448c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 145483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14581237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14591237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14601237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1464aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1465aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 14660fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 14670fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 14680fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 14690fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 14701d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 14711d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 14721d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 147342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 14745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1475e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1476aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 14772333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can compound literals be value-dependent? 147842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 14791d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall QualType T, Expr *init, bool fileScope) 14801d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall : Expr(CompoundLiteralExprClass, T, 148142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall tinfo->getType()->isDependentType(), false), 148242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1484ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1485ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1486ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1487ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 14885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 14895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1490ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1491e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1492e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1493ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1494ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 14950fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1496ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1497ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 149842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 149942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 150042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 150173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 15020fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 15030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 15040fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 15050fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 150673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 15070fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 150873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1509aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1512aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1513aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15151237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15161237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15171237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1518aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1519aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 152049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 152149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 152249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 152349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 15240835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 1525cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 1526cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CastKind - the kind of cast this represents. 1527cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson enum CastKind { 1528cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_Unknown - Unknown cast kind. 15291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// FIXME: The goal is to get rid of this and make all casts have a 1530cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// kind so that the AST client doesn't have to try to figure out what's 1531cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// going on. 1532cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_Unknown, 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1534cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_BitCast - Used for reinterpret_cast. 1535cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_BitCast, 15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1537cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_NoOp - Used for const_cast. 15383503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson CK_NoOp, 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 154011de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson /// CK_BaseToDerived - Base to derived class casts. 154111de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson CK_BaseToDerived, 154211de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson 15433503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson /// CK_DerivedToBase - Derived to base class casts. 1544714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson CK_DerivedToBase, 15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1546714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson /// CK_Dynamic - Dynamic cast. 15474d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson CK_Dynamic, 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15494d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson /// CK_ToUnion - Cast to union (GCC extension). 1550112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson CK_ToUnion, 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1552112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson /// CK_ArrayToPointerDecay - Array to pointer decay. 155327a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_ArrayToPointerDecay, 15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1555b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson // CK_FunctionToPointerDecay - Function to pointer decay. 1556b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson CK_FunctionToPointerDecay, 15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155827a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_NullToMemberPointer - Null pointer to member pointer. 155927a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_NullToMemberPointer, 15601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 156127a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 156227a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// member pointer in derived class. 15639099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian CK_BaseToDerivedMemberPointer, 15649099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian 15651a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 15661a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson /// member pointer in base class. 15671a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson CK_DerivedToBaseMemberPointer, 15681a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson 15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// CK_UserDefinedConversion - Conversion using a user defined type 157058d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian /// conversion function. 15717fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian CK_UserDefinedConversion, 15727fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian 15737fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian /// CK_ConstructorConversion - Conversion by constructor 15747f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_ConstructorConversion, 15757f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 15767f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_IntegralToPointer - Integral to pointer 15777f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_IntegralToPointer, 15787f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 15797f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_PointerToIntegral - Pointer to integral 1580ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson CK_PointerToIntegral, 1581ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson 1582ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson /// CK_ToVoid - Cast to void. 158316a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson CK_ToVoid, 158416a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson 158516a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// CK_VectorSplat - Casting from an integer/floating type to an extended 158616a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// vector type with the same element type as the src type. Splats the 1587f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson /// src expression into the destination expression. 158882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_VectorSplat, 158982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 159082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralCast - Casting between integral types of different size. 159182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralCast, 159282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 159382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralToFloating - Integral to floating point. 159482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralToFloating, 159582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 159682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingToIntegral - Floating point to integral. 159782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_FloatingToIntegral, 159882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 159982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingCast - Casting between floating types of different size. 1600bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson CK_FloatingCast, 1601bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson 1602bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson /// CK_MemberPointerToBoolean - Member pointer to boolean 160392ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian CK_MemberPointerToBoolean, 160492ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian 160592ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c 160692ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian /// pointer 16073b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian CK_AnyPointerToObjCPointerCast, 16083b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block 16093b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian /// pointer 16103b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian CK_AnyPointerToBlockPointerCast 1611bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson 1612cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson }; 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1614cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 1615cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind Kind; 16160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 16170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 1618c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op) : 1619898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1620898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1621898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1622898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1623898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1624898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 1626c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson Kind(kind), Op(op) {} 16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1628087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CastExpr(StmtClass SC, EmptyShell Empty) 1630087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : Expr(SC, Empty) { } 16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16320835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 1633cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind getCastKind() const { return Kind; } 1634cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson void setCastKind(CastKind K) { Kind = K; } 1635f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 1636f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 16370835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 16380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 1639087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 1640087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 16416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 16426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 16436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 16446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 16456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 16466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 16476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 16486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16509d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 16519d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 16529d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 16539d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 16546eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 16550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 16569d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 16579d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 16580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 16590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 16620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 16630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 16640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 16650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 166649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 166749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 166849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 166949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 167049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1671bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1672bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1673bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1674bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1675bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1676bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1677bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 1679bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1680bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1681bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 16820835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1683eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1684eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1685eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 168649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 1687c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, bool Lvalue) : 1688c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson CastExpr(ImplicitCastExprClass, ty, kind, op), LvalueCast(Lvalue) { } 168990045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1690087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitCastExpr(EmptyShell Shell) 1692087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : CastExpr(ImplicitCastExprClass, Shell) { } 1693087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 1694087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 16950835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 16960835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 16970835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 169890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1699eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1700eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1701eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1702eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1703eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1704eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 170749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 170849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 170949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 171049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 171149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 171349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 171449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 171549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 171649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 171749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 171849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 17195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 172049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 172149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 172249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 172349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 172449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 172549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 172649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 17270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 17289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 17299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 17309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 173149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 173249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 1733c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 17349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall Expr *op, TypeSourceInfo *writtenTy) 17359d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall : CastExpr(SC, exprTy, kind, op), TInfo(writtenTy) {} 173649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 1737db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExplicitCastExpr(StmtClass SC, EmptyShell Shell) 1739db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : CastExpr(SC, Shell) { } 1740db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 174149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 17429d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 17439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 17449d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 17459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 17469d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 174749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 174849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 17499d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 175049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17529d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 175309cc141c89a5e9f305c17d7a88298647df16ceddJohn McCall if (SC >= CStyleCastExprClass && SC <= CStyleCastExprClass) 17549d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 17559d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 175649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 17579d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 17589d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 175949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 176049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 176149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 176249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 17636eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 176449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 176549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 17666eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1767b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1768b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17709d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, 17719d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *writtenTy, 17729d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall SourceLocation l, SourceLocation r) : 17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, writtenTy), 1774b2f9e516327310d95840d442416084508f80c183Steve Naroff LPLoc(l), RPLoc(r) {} 177549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1776db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CStyleCastExpr(EmptyShell Shell) 1778db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : ExplicitCastExpr(CStyleCastExprClass, Shell) { } 1779db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1780b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1781db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 1782db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1783b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 1784db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 1785db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1787b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 17915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17926eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 17963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 17973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 17983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 17993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 18003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 18013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 18023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 18033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 18043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 18053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 18063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 18073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 18083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 18093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 18103fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 18113fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 18123fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 18135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 18145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 181703d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1818224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 18215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 18225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 18235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 18255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 18265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 18275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 18305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 18315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 18325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 18345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 18355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 18365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 183717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 183817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 18395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 184017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 184117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 18421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 184517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1846898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1847898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 1849898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 18501237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 18511237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 18521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 18535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 18545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1856db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 18571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 1858db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 1859db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 186017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 1861db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 1862db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 1864db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 1865db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1867db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 18685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1869db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 1870db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1879063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1880063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1881063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1882063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1883063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1884063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1885063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1886063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 18875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 189040a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; } 189140a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek bool isShiftOp() const { return isShiftOp(Opc); } 1892aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 1893aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; } 1894aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isBitwiseOp() const { return isBitwiseOp(Opc); } 1895f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1896f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1897f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1898f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1900f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 19011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1902aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; } 1903aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl bool isComparisonOp() const { return isComparisonOp(Opc); } 1904aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 1905f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1906f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1907f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 19105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 1913eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump S->getStmtClass() == CompoundAssignOperatorClass; 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 19171237c673c07f9d827129ba02720108816abde562Ted Kremenek 19181237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 19191237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 19201237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 19211237c673c07f9d827129ba02720108816abde562Ted Kremenek 19225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 192317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 19242333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 19252333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(CompoundAssignOperatorClass, ResTy, 19262333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 19272333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isValueDependent() || rhs->isValueDependent()), 19282333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 19291237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 19301237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 19315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1932ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 1934ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(SC, Empty), Opc(MulAssign) { } 19355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 19385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 19395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 1944ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 1945ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 19465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 1948ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 1949ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 195017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 195117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 1952ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 1953ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 19541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1958ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 1959ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 1960ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 1961ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1962ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 1963ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 1964ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 1965ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 1966ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 1967ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1968ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 1969ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 1970ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 19745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 19811237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 19825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 198347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 198547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 198647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation CLoc, Expr *rhs, QualType t) 1987898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 1988898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 1989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 1990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 1991898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 1993898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 199447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 199547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 199647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 19971237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 19981237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 19991237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 20001237c673c07f9d827129ba02720108816abde562Ted Kremenek } 20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2002ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2003ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 2004ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 2005ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2006395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 2007395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 20085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2009ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 2010395a2abf0028968d85958610e393e067885dc14fTed Kremenek 2011395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2012395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 2013395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 2014395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 2015395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // is only evaluated once. 2017395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 20185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 2019395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 20201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2021395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2022395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 20235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 20241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 2026ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2027ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2029ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 20305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 203147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 203247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 203347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 203447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 203547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 203647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 20375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 20385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 20425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 20441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20451237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20461237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20471237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 20485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20506481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 20516481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20556481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 20566481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 20572333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(AddrLabelExprClass, t, false, false), 20582333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20607d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 20627d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 20637d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 20647d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 20657d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 20667d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 20677d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 20687d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 20705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 20747d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 20757d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 20765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 20771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 20785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20796481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20811237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20821237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20831237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 20845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2085ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2086ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2087ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2088ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2089ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 20905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2091ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2092ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 20932333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2094d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2095d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 20962333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(StmtExprClass, T, T->isDependentType(), false), 20972333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20996a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 21006a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 21016a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 21025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 21035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 21046a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 21056a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2106ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2107ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2108ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 21091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2110026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 21116a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2112026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 21136a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2115ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2117ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2118ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21201237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 21211237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 21221237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2123ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2124ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2125dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2126d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2127d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2128d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2129d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 2130d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 2131d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 2132363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2133d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType t1, QualType t2, SourceLocation RP) : 21362333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(TypesCompatibleExprClass, ReturnType, false, false), 21372333f7727f97018d6742e1e0938133bcfad967abEli Friedman Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2138d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 213944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 214044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 214144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 214244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 21437f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 214444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType1(QualType T) { Type1 = T; } 21457f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 214644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType2(QualType T) { Type2 = T; } 21471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 214844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 214944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 215144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 215244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 21531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2154d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2155363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2156d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2157d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2159d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2160d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21621237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 21631237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 21641237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2165d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2166d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2167d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2168d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2169d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2170d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2171d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2172d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2173d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2174d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2175d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2176d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2177d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2178d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2179d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 21805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2181d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2182d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2183888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected: 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 2185888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2186d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 21872333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 21882333f7727f97018d6742e1e0938133bcfad967abEli Friedman // to be computed differently? 2189a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 21922333f7727f97018d6742e1e0938133bcfad967abEli Friedman Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false), 21932333f7727f97018d6742e1e0938133bcfad967abEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2195a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2196d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2197d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2198d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 219994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 220094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 220294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 220394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 220494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 220594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 220794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 220894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 220994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2210d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2211d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2212d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2213d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 22141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2215d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2216d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 22171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2218888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman ~ShuffleVectorExpr() {} 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2220d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2221d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2222d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2223d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 22241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2225d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2226d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2227d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 22285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2229d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2230d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2231d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 22325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2233d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2235888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 223694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2237dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2238dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 22399a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2240d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 22411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2242d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2243d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2244d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2245d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2246d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2247d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2249d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 22507976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 22517976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 22527976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 22537976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 22547976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 22557976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2256d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 22571237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 22585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2259d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2260d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2261d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2262ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2263ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 22641237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 22651237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 22661237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 22671237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 22681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 22697976932a1c256d447316ffac58e9821417725e34Eli Friedman 227044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 227144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 227244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 22737976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 22747976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 227527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 22767976932a1c256d447316ffac58e9821417725e34Eli Friedman 22777976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 22787976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 22797976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 22807976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 22817976932a1c256d447316ffac58e9821417725e34Eli Friedman } 22827976932a1c256d447316ffac58e9821417725e34Eli Friedman 22835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 228444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 22855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 228644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 22875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 228844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 228944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 229044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 229144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 229344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 229444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 22951237c673c07f9d827129ba02720108816abde562Ted Kremenek 2296d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2297d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2298d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2299d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2301d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2302d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23041237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 23051237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 23061237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2307d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2308d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 23092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 23102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 23112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 23122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 23132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 23142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 23152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 23162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 23172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 23182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 23192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 23201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 23212333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { } 23222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 232344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 232444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 232544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 23262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 23272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 232844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 23292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 23302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 23312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 23322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 23332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 23352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 23362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 23392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 23402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 23412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 23422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 23437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start. 23447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 23455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 23467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 23477c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 23487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 23492333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(VAArgExprClass, t, t->isDependentType(), false), 23507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 23517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 23527c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 23531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2354d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Create an empty __builtin_va_start expression. 2355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2356d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 23575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 23585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2359d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2360d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2361d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2362d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2364d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2365d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2366d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 23677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 23687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 23707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 23717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 23727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 23737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 23741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 23767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 23771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 23787c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 23791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 23814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 23824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 23834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 23844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 23854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 23864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 23874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 23884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2389196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 23904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 23914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 23924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 23934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 23944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 23954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 23964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 23974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2398196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 23994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 24004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 24014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 24024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 24034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 24044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 24054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 24063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 24074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 24084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 24094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2410196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 24114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 24124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 24134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 24144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 24154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 24164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 241766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 241841ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor // FIXME: Eliminate this vector in favor of ASTContext allocation 24195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek std::vector<Stmt *> InitExprs; 242066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 24211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 24234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 24244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 24254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 24260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 24270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 24280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 24290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2430a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2431a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2432a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2433a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 243466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 243566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 24364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc); 2437d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2438d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2439d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { } 24401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2441c5ae899b4bbf65488445316c63168079177db0edSteve Naroff unsigned getNumInits() const { return InitExprs.size(); } 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getInit(unsigned Init) const { 2444c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 24454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 244666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getInit(unsigned Init) { 2449c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 24504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 245166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2454c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 24559e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 24569e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2457c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2458fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2459fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor void reserveInits(unsigned NumInits); 24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 24624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 24634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 24644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 24654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 24664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 24674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 24684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 24694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 24704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 24714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 24724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 24734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 24744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 24754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 24764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *updateInit(unsigned Init, Expr *expr); 2477c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 24780bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 24790bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 24800bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 24810bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 24820bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 24830bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 24840bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 24850bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 24860bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2487c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2488c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2489b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2490b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2491b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2493d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2494d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2495d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 249687fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 249787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 24984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 24994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 25004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 25011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 25024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 25034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 25044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2505a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 25061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 2507d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 2508a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 2509a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 251066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 251166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 251366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 25141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 251566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 251666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 251866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 251966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 252066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25227fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::iterator iterator; 25237fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::reverse_iterator reverse_iterator; 25241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25257fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator begin() { return InitExprs.begin(); } 25267fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator end() { return InitExprs.end(); } 25277fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 25287fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rend() { return InitExprs.rend(); } 252966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 253066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 253105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 253205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 253305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 253405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 253505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 253605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 253705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 25381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 253905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 254005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 254105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 254205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 254305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 254405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 254505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 254605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 254705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 254805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 254905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 255005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 255105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 2552ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 2553ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 2554ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 2555ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2556ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 255705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 255805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 255905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 256005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2561eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 256205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 2563eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 256405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 256505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 256605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 256705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2568ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 2569ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 2570ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 2571ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 257205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 257305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 257405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 257505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 257605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2577ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2578319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 2579ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 2580eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 25819ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 25829ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 258305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2584d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 2585d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 2586d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 2587d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 258842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 25891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 259042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 2591319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void DestroyDesignators(ASTContext &C); 2592319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor 259305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 259405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 259505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 259605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 259705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 259805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 259905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 260005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 260105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 260205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 26031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 260405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 260505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 260705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 260805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 260905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 261005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 261105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 261205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 261305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 261405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 261505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 261605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 261705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 261805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 261905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 262005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 262105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 262305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 262405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 262505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 262605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 262705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 262805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 262905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 263005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 263105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 263205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 263305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 263405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 263505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 263605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 263705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 263805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 263905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 264005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 264105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 264205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 264305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 264405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 264505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 264605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 264705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 2648ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 2649ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 265005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 265305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 265405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 265505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 265605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 265705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 265805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 265905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 26601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 266105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 266205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 266305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 266405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 266505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 266605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 266705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 266805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 266905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 26701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 267105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 267205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 267305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 267405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 267505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 267605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 267705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 267805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 267905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 268005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 268105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 268205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 268305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 268405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 268505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 268605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 268705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 268805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 268905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 269005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 269105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 269205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 269305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 269405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 269505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 269605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 269705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 269887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 269987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 270087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 270187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 270287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 270305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 270405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 270505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 270605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 270705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 270805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 270905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 271005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 271105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 271205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 271305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 271405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 271505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 271605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 271705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 271805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 271905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 272005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 272105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 272205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 272305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 272405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 27254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2726d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 2727d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 2728d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 2729d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 2730d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2731d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 27324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 27334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 27344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 27354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 27364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 27374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 273805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 273905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 274105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 274205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 274305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 2744eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 274505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2746d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 2747d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 274805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 274905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 275005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 275105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 275205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 2753ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 27541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 2756ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 275705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2758711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 2759711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 2760319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void setDesignators(ASTContext &C, const Designator *Desigs, 2761319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 2762d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 276305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 276405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 276505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 276605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 276705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 276805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 276905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 2770d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 277105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 277205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 2773eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 2774eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 2775d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 277605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 277705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 27781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 277905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 278005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 278105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 278205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 278305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 278405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 278505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2786d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 2787d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 2788d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 2789d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 2790d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 2791d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2792d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 2793d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2794d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2795d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2796d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 2797d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2798d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2799d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 2800d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2801d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2802d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2803d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 2804d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2805d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2806ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 2807ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 2808319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 2809ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 2810ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 281105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 281205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 281305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 281505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 281605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 281705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 281805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 281905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 28213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 28223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 28233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 28243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 28253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 28261a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 28271a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 28283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 28291a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 28301a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 28323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 28331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 28342333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ImplicitValueInitExprClass, ty, false, false) { } 28353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 2836d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 2837d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 2838d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 2839d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 28401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 28423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 28433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 28443498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 28453498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 28463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 28473498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 28483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 28493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 28503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 285205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 285305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 28542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 28562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 28572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 28582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 28592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected: 28612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual void DoDestroy(ASTContext& C); 28621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 28652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 28662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman ~ParenListExpr() {} 28682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 28702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 28711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 28731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 28752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 28762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 28772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 28802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 28812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 28822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 28832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 288483ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 28872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 28882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 28902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 28911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 28931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 28942ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 28952ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 28961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 28982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 28992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 29002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 29012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 29021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 29044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 29054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 29064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2907a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2908a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 2909a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 2910a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 2911a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 291273525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 291373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 291473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 2915a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 2916a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 2917d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 2918a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 2919a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 2920a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 2921a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 29222333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(), 29232333f7727f97018d6742e1e0938133bcfad967abEli Friedman base->isValueDependent()), 2924d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 29251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2926d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 2927d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 2928d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 2929d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2930a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 2931a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 2932d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 2933d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2934d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 2935d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 2936d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2937d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 2938d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 2939d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2940a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 2941a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 29421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2943a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 2944a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 2945a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2947a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 2948a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 2949a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2951a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 2952a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 2953a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29552140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 29562140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 29572140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 29581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 2961a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2962a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 29631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2964a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 2965a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 2966a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 2967a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 2968a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2969a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 297056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 29719c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 29724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 297356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 297456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 2975b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 29764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 2977b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 29782333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockExprClass, ty, ty->isDependentType(), false), 2979b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 29809c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 298184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 298284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 298384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 2984d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 298556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 298684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 298784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 298856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 298956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 299056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 299156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 29929c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 29939c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 299456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 29959c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 29969c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 299756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 299856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 299956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 3000b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 30015b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 3002b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 300384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3004b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 30051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30069c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 30074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 30084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 30091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 30114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 30124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 30134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 30141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30154eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 30164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 30174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 30194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 30207d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 30217d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 30224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 30232333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Fix type/value dependence! 30241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 30252333f7727f97018d6742e1e0938133bcfad967abEli Friedman bool constAdded = false) 30262333f7727f97018d6742e1e0938133bcfad967abEli Friedman : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef), 30272333f7727f97018d6742e1e0938133bcfad967abEli Friedman ConstQualAdded(constAdded) {} 302894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 302994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 303094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 303194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 303294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 30331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 30354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 303694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 303794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 303894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 303994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 304094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 30414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 30421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 304494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 30451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30467d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 30477d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 304894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 30491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 30514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 30524eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 30531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 30554eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 30564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 30574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 30584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 30595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 30605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 30615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3062