Expr.h revision a2813cec2605ce7878d1b13471d685f689b251af
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; 3788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 44898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected: 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// TypeDependent - Whether this expression is type-dependent 47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// ValueDependent - Whether this expression is value-dependent 51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 52898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor should go away and we should 55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // require every subclass to provide type/value-dependence 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // information. 571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr(StmtClass SC, QualType T) 58b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(false), ValueDependent(false) { 591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump setType(T); 6083233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor } 61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T, bool TD, bool VD) 63b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(TD), ValueDependent(VD) { 64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 7143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// \brief Increases the reference count for this expression. 7243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// 7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// Invoke the Retain() operation when this expression 7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor /// is being shared by another owner. 7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Expr *Retain() { 7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor Stmt::Retain(); 7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor return this; 7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor } 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((TR.isNull() || !TR->isReferenceType()) && 908320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 91f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValueDependent(bool VD) { ValueDependent = VD; } 1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setTypeDependent(bool TD) { TypeDependent = TD; } 1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 133026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 13740b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis SourceRange &R2) const; 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 14808ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 14976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 155fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 15686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 15786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_MemberFunction 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 15928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 16053202857c60214d80950a975e6e52aebf30bd16aEli Friedman 16153202857c60214d80950a975e6e52aebf30bd16aEli Friedman // Same as above, but excluding checks for non-object and void types in C 16253202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult isLvalueInternal(ASTContext &Ctx) const; 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 16944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 17044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 17144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 17244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 177fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 179ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1824f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1835daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 184ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 18586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 18686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_MemberFunction 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 18844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 18944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 19233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 19333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 19638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 19738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 1981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 203590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 204590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 206590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 2078070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 208590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 210c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 211c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 212c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 2162d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 22194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 22494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 22594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 22694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 22794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 22894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 23094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 23194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 23294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 23394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 23694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 23794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2386ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 239019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 240019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 241019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2425b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2435b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 2446ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 24545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 24645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 247c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 24851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 24951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 25051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 25151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 252b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 253b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 2541b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 2551b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 256b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it 257b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// also succeeds on stack based, immutable address lvalues. 258b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 259b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman 260ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 261ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 262ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 263ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 264ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 265ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 266ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 267ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 268ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 269ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 270ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 271ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 272ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 273ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 274ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 275efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 276efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 277efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 278ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 279ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 280efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 28144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 283102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 2841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 2874e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 2884e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 2894e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* IgnoreParens(); 29056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 29156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 29227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 29356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 295ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 296ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 297ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 298ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3004e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek const Expr* IgnoreParens() const { 3014e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 3024e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 30356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 30456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 30556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 306ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 307ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 308ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 312898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 326a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 327a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 328a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 329a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 330a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 331a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 332a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 333a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 334a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 335a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 336a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 337a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 338a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 339a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 340a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 341a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 342a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 343a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 344a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 345a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 346a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 347a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 348a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 349a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 350a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor TemplateArgument *getTemplateArgs() { 351a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<TemplateArgument *> (this + 1); 352a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 353a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 354a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 355a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const TemplateArgument *getTemplateArgs() const { 356a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<const TemplateArgument *> (this + 1); 357a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 358a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 359a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 363a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 364a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 365a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 366a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 367a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Flag on DecoratedD that specifies when this declaration reference 368a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 369a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 370a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 371a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 372a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // DecoratedD - The declaration that we are referencing, plus two bits to 373a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 374a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // (2) the declaration's name was followed by an explicit template 375a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 376a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor llvm::PointerIntPair<NamedDecl *, 2> DecoratedD; 377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 378a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3809e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 381a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 382a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 383a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (DecoratedD.getInt() & HasQualifierFlag == 0) 384a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 386a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 387a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 388a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 389a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 390a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 391a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 392a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 393a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 394a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 395a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 396a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 397a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag == 0) 398a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 399a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 400a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (DecoratedD.getInt() & HasQualifierFlag == 0) 401a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 402a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 403a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 404a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor getNameQualifier() + 1); 405a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 406a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 407a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the explicit template argument list that followed the 408a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member template name, if any. 409a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 410a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList(); 411a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 412a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 413a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 414a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NamedDecl *D, SourceLocation NameLoc, 415a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool HasExplicitTemplateArgumentList, 416a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc, 417a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const TemplateArgument *ExplicitTemplateArgs, 418a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumExplicitTemplateArgs, 419a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc, 420a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor QualType T, bool TD, bool VD); 421a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 4229e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 4231a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // FIXME: Eventually, this constructor will go away and all subclasses 4241a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // will have to provide the type- and value-dependent flags. 4258e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) : 426a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Expr(SC, t), DecoratedD(d, 0), Loc(l) {} 4279e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 4281a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD, 4291a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor bool VD) : 430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Expr(SC, t, TD, VD), DecoratedD(d, 0), Loc(l) {} 4311a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 433898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor will go away and all clients 434898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // will have to provide the type- and value-dependent flags. 4351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) : 436a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Expr(DeclRefExprClass, t), DecoratedD(d, 0), Loc(l) {} 437898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) : 439a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Expr(DeclRefExprClass, t, TD, VD), DecoratedD(d, 0), Loc(l) {} 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty declaration reference expression. 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit DeclRefExpr(EmptyShell Empty) 4430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(DeclRefExprClass, Empty) { } 4440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 445a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 446a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 447a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 448a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NamedDecl *D, 449a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 450a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor QualType T, bool TD, bool VD); 451a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 452a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 453a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 454a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 455a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NamedDecl *D, 456a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 457a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool HasExplicitTemplateArgumentList, 458a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc, 459a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const TemplateArgument *ExplicitTemplateArgs, 460a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumExplicitTemplateArgs, 461a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc, 462a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor QualType T, bool TD, bool VD); 463a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 464a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NamedDecl *getDecl() { return DecoratedD.getPointer(); } 465a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NamedDecl *getDecl() const { return DecoratedD.getPointer(); } 466a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor void setDecl(NamedDecl *NewD) { DecoratedD.setPointer(NewD); } 467904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 4689e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 4690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 470a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 472a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 475a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 476a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 477a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 478a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 479a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 482a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 485a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the nested-name-specifier 487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 488a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 491a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 492a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 495a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determines whether this member expression actually had a C++ 496a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasExplicitTemplateArgumentList() const { 498a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag; 499a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 500a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 501a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 503a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 504a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 506a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 507a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 508a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 509a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 512a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const TemplateArgument *getTemplateArgs() const { 513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 514a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 517a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 524a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 530a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasExplicitTemplateArgumentList()) 532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 533a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 534a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 536a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5389e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis return T->getStmtClass() == DeclRefExprClass || 539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor T->getStmtClass() == CXXConditionDeclExprClass; 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 5421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 54477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 54577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 548d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 549d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 550227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 551227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 552227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 553227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 554cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor PrettyFunction 555227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 558227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 559227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 560227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 562773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson : Expr(PredefinedExprClass, type, type->isDependentType(), 563773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson type->isDependentType()), Loc(l), Type(IT) {} 5641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 56717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 56817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 569227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 57017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 57117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 57217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 57317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 57417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 5753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson static std::string ComputeName(ASTContext &Context, IdentType IT, 5763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const Decl *CurrentDecl); 5773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 578227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 579227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 582227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 583d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 58677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 58777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 588227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 589227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 600a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 6010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit IntegerLiteral(EmptyShell Empty) 6030b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 6040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 608313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 609313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 610313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 6110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 6120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 62077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 62177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 627c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 630c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 631c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) { 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6330b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6340b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 6350b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 6360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 637018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 638c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 6450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 6460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 6470b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 65277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 65377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 65477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 65577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 659525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 660720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FloatingLiteral(const llvm::APFloat &V, bool isexact, 664720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(FloatingLiteralClass, Type), Value(V), IsExact(isexact), Loc(L) {} 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 66717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 66917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 67017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 671c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 67217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setValue(const llvm::APFloat &Val) { Value = Val; } 67317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 674720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 67517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 676c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 677da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 678da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 679da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 680da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 68317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 68417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 6854863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // FIXME: The logic for computing the value of a predefined expr should go 6864863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // into a method here that takes the inner-most code decl (a block, function 6874863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // or objc method) that the expr lives in. This would allow sema and codegen 6884863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // to be consistent for things like sizeof(__func__) etc. 6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 6961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 69877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 69977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7025d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 7035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 7045d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 7055d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 7065d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 7075d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 7085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 7095d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 7105d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 7115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 713cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 715cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 716cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 7185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 719cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 720cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 7215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 7245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 7255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7275d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 7285d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 7295d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 7305d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 7315d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 732e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 733e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 734e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 735a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 736c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 737c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 738690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 739690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 7408bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 741690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 742c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 743c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 744c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 745c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 746c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 747c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 752726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 753726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 7542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 7552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {} 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 75842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext &C); 75942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 7622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 7632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 7642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 765a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 7662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 7672085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 7692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 7702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 7712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 7722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 773a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 774673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 775673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 776673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 777b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 778b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 779b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 780b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar // FIXME: These are deprecated, replace with StringRef. 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 783673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 784673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 785b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 786673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 788673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 789673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 7908d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 791b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 792b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 793b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 79433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 79533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 79633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 797726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 798726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 799726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 801726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 802726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 803726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 804726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 806673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 807673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 808673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 809673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 810b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 811b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 812b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 82377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 82477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 8315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 834898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 8351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 836898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 838c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 840c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 841c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 8425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 8435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 844c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 845c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 846866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 848313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 849313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 850c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 851313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 852313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 853313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 854c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 855313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 86277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 86377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 8680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 870dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 871dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 872dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 873dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 874dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 875dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 876dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 87773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subexpression is a compound literal with the various MemberExpr and 87973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 88073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 88313d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 89173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 89273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 8955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 9019103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 9029103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 9049103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 9080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 9090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 9110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 9120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 9140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 9150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 9180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 9190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 9212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 9222085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 9232085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9255a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 9262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 9272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 9282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 9295a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 9305a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 9325d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 9345a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isArithmeticOp() const { return isArithmeticOp(Opc); } 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 942bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 943bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 944bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 945bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 946bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 947bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 948bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 949bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 96577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 9690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 9700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 9710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 9720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 973d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 974d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl void *Ty; 975d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 976d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 97842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 97942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 98042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 98142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, QualType T, 9840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 9850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 9862850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 987ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 9882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 989ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor T->isDependentType()), 990ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 991ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ty = T.getAsOpaquePtr(); 992ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 993ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 995ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 996ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 997ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 998ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 999ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1000ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1001ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1002ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1003d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 10040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 10050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 10060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 10070b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 10080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 10100b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 10110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 10130518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 10140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 1015d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return QualType::getFromOpaquePtr(Argument.Ty); 10160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1017caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 10180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1019d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 10200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1021caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1022caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1023caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 10240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setArgument(QualType T) { 10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Argument.Ty = T.getAsOpaquePtr(); 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 10290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 10300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 10320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 10330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 10340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 10350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 10360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 103776e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 10380b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 10390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 10400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 10410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1042866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1043866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1044866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1045866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 105377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 105477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 106377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10672324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 106873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 10692850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 10702850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 10712850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 10722850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 107373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 107473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 107573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1077cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1078cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1079cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1080cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 10812324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 10822324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 10832324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 10842324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 10852324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 108633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 108733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 108833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 108933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 10905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 10915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1092cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1093cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 10945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 10955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1096cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 10995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 110077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 11011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 11035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 11042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 11075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11082324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 11115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 111577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1118026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1119cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1120cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11215cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 112977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 113077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1134b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1136b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1138b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1139b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 114177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 11425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1146b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1147b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1148668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1149668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 115042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 115142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor virtual void DoDestroy(ASTContext& C); 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11571f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1158ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 11591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1160668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 11635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 116418b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1165a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1166a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1167a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1168bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1169bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1170bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1171a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 11795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 11835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1186934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1187934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1188934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1189934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1190934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1192d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1193d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1194d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 11958189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 11985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1200d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1201d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 12025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 12035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1209cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1210cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 12113c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 12156dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 12166dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1218d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 12191f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1220866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 122277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1226b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 122788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() == CXXMemberCallExprClass; 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 123188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 123288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 123388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 123477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 123577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 123677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1239ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 1242ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1243ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 12445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1246ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1247ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 124886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *MemberDecl; 12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1250ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1253ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 125483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// refer to the member, e.g., "x->Base::f". When true, a NameQualifier 1258c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 125983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool HasQualifier : 1; 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1261c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1262c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1263c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1264c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 1265c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the NameQualifier structure. 1266c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 126883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 126983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NameQualifier *getMemberQualifier() { 127083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 127183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 127483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 127583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 127683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 127783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor const NameQualifier *getMemberQualifier() const { 1278c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1279c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1281c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1282c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1283c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1284c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 128583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1287c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasQualifier) 1288c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1290c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return reinterpret_cast<ExplicitTemplateArgumentList *>( 1291c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor getMemberQualifier() + 1); 1292c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1294c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the explicit template argument list that followed the 1295c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member template name, if any. 1296c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1297c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList(); 129883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual, 130183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, NamedDecl *memberdecl, SourceLocation l, 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool has_explicit, SourceLocation langle, 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *targs, unsigned numtargs, 13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation rangle, QualType ty); 130583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 130786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l, 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ty) 13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 1310ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 131183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 1312c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor HasQualifier(false), HasExplicitTemplateArgumentList(false) {} 1313510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 13141f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty member reference expression. 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit MemberExpr(EmptyShell Empty) 13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, Empty), HasQualifier(false), 1317e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor HasExplicitTemplateArgumentList(false) { } 13181f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 132083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamedDecl *memberdecl, 1322c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation l, 1323c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool has_explicit, 1324c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation langle, 1325c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const TemplateArgument *targs, 1326c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor unsigned numtargs, 1327c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation rangle, 1328c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty); 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 13315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 133257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 133357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 133457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 133557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 133657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 133786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *getMemberDecl() const { return MemberDecl; } 133888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setMemberDecl(NamedDecl *D) { MemberDecl = D; } 13391f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 13410979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 13420979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 134383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool hasQualifier() const { return HasQualifier; } 13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 134683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 134783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 134983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 135083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 135383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 135683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 135783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 135983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (!HasQualifier) 136083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 136383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1364c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1365c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1366c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasExplicitTemplateArgumentList() { 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1369c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1372c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1374c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1375c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1377c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->LAngleLoc; 1378c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1380c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1381c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getTemplateArgs() const { 1383c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1386c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->getTemplateArgs(); 1387c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1389c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1390c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1392c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1395c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->NumTemplateArgs; 1396c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1399c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1401c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1402c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1404c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return getExplicitTemplateArgumentList()->RAngleLoc; 1405c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 14081f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 14091f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1410ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1411ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1412026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 14131f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 141672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 141772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 1418c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation EndLoc = MemberLoc; 1419c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (HasExplicitTemplateArgumentList) 1420c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor EndLoc = getRAngleLoc(); 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 142272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 142372527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1424c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1425c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 143183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14351237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14361237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14371237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1441aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1442aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 14430fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 14440fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 14450fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 14460fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 14475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1448e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1449aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 1450a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, 1451a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool fileScope) 1452a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), 1453a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner FileScope(fileScope) {} 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1455ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1456ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1457ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1458ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 14595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 14605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1461ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1462e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1463e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1464ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1465ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 14660fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1467ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1468ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 146973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 14700fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 14710fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 14720fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 14730fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 147473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 14750fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 147673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1477aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1480aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1481aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14831237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14841237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14851237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1486aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1487aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 148849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 148949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 149049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 149149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 14920835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 1493cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 1494cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CastKind - the kind of cast this represents. 1495cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson enum CastKind { 1496cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_Unknown - Unknown cast kind. 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// FIXME: The goal is to get rid of this and make all casts have a 1498cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// kind so that the AST client doesn't have to try to figure out what's 1499cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// going on. 1500cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_Unknown, 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1502cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_BitCast - Used for reinterpret_cast. 1503cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CK_BitCast, 15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1505cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson /// CK_NoOp - Used for const_cast. 15063503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson CK_NoOp, 15071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15083503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson /// CK_DerivedToBase - Derived to base class casts. 1509714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson CK_DerivedToBase, 15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1511714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson /// CK_Dynamic - Dynamic cast. 15124d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson CK_Dynamic, 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15144d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson /// CK_ToUnion - Cast to union (GCC extension). 1515112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson CK_ToUnion, 15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1517112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson /// CK_ArrayToPointerDecay - Array to pointer decay. 151827a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_ArrayToPointerDecay, 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1520b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson // CK_FunctionToPointerDecay - Function to pointer decay. 1521b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson CK_FunctionToPointerDecay, 15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152327a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_NullToMemberPointer - Null pointer to member pointer. 152427a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson CK_NullToMemberPointer, 15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 152627a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 152727a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson /// member pointer in derived class. 15289099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian CK_BaseToDerivedMemberPointer, 15299099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// CK_UserDefinedConversion - Conversion using a user defined type 153158d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian /// conversion function. 15327fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian CK_UserDefinedConversion, 15337fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian 15347fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian /// CK_ConstructorConversion - Conversion by constructor 15357f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_ConstructorConversion, 15367f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 15377f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_IntegralToPointer - Integral to pointer 15387f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson CK_IntegralToPointer, 15397f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson 15407f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson /// CK_PointerToIntegral - Pointer to integral 1541ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson CK_PointerToIntegral, 1542ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson 1543ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson /// CK_ToVoid - Cast to void. 154416a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson CK_ToVoid, 154516a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson 154616a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// CK_VectorSplat - Casting from an integer/floating type to an extended 154716a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson /// vector type with the same element type as the src type. Splats the 1548f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson /// src expression into the destination expression. 154982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_VectorSplat, 155082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 155182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralCast - Casting between integral types of different size. 155282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralCast, 155382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 155482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_IntegralToFloating - Integral to floating point. 155582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_IntegralToFloating, 155682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 155782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingToIntegral - Floating point to integral. 155882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_FloatingToIntegral, 155982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson 156082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson /// CK_FloatingCast - Casting between floating types of different size. 156182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson CK_FloatingCast 1562cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson }; 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1564cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 1565cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind Kind; 15660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 15670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 1568c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op) : 1569898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1571898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1572898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1573898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1574898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 1576c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson Kind(kind), Op(op) {} 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1578087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CastExpr(StmtClass SC, EmptyShell Empty) 1580087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : Expr(SC, Empty) { } 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15820835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 1583cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson CastKind getCastKind() const { return Kind; } 1584cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson void setCastKind(CastKind K) { Kind = K; } 1585f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 1586f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 15870835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 15880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 1589087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 1590087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15929d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 15939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 15949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 15959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 15966eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 15970835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 15989d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 15999d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 16000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 16010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 16040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 16050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 16060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 16070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 160849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 160949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 161049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 161149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 161249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1613bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1614bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1615bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1616bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1617bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1618bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1619bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 1621bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1622bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1623bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 16240835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1625eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1626eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1627eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 162849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 1629c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, bool Lvalue) : 1630c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson CastExpr(ImplicitCastExprClass, ty, kind, op), LvalueCast(Lvalue) { } 163190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1632087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitCastExpr(EmptyShell Shell) 1634087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : CastExpr(ImplicitCastExprClass, Shell) { } 1635087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 1636087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 16370835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 16380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 16390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 164090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1641eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1642eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1643eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1644eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1645eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1646eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 16471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 164949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 165049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 165149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 165249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 165349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 165549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 165649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 165749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 165849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 165949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 166049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 166249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 166349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 166449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 166549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 166649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 166749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 166849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 16690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 167049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// TypeAsWritten - The type that this expression is casting to, as 167149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// written in the source code. 167249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType TypeAsWritten; 167349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 167449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 1675c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *op, QualType writtenTy) 1677c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson : CastExpr(SC, exprTy, kind, op), TypeAsWritten(writtenTy) {} 167849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 1679db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExplicitCastExpr(StmtClass SC, EmptyShell Shell) 1681db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : CastExpr(SC, Shell) { } 1682db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 168349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 168449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 168549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 168649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType getTypeAsWritten() const { return TypeAsWritten; } 1687db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setTypeAsWritten(QualType T) { TypeAsWritten = T; } 168849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 16916eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass) 16929d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 16939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 169449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 16959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 16969d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 169749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 169849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 169949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 170049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 17016eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 170249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 170349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 17046eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1705b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1706b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, QualType writtenTy, 17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation l, SourceLocation r) : 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, writtenTy), 1711b2f9e516327310d95840d442416084508f80c183Steve Naroff LPLoc(l), RPLoc(r) {} 171249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1713db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CStyleCastExpr(EmptyShell Shell) 1715db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : ExplicitCastExpr(CStyleCastExprClass, Shell) { } 1716db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1717b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1718db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 1719db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1720b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 1721db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 1722db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 17235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1724b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 17255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17296eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 17333fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 17343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 17353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 17363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 17373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 17383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 17393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 17403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 17413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 17423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 17433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 17443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 17453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 17463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 17473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 17483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 17493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 175403d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1755224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 17565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 17575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 17615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 17625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 17635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 17735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 177417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 177517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 17765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 177717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 177817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 178217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1783898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1784898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 1786898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 17871237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 17881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 17915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1793db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 1795db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 1796db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 179717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 1798db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 1799db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 1801db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 1802db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1804db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 18055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1806db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 1807db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 18105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 18135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 18145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1816063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1817063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1818063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1819063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1820063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1821063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1822063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1823063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 18255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 18265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 182740a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; } 182840a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek bool isShiftOp() const { return isShiftOp(Opc); } 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 1830f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1831f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1832f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1833f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1835f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1837f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1838f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1839f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 18405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 18415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 1845eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump S->getStmtClass() == CompoundAssignOperatorClass; 18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 18491237c673c07f9d827129ba02720108816abde562Ted Kremenek 18501237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 18511237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 18521237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 18531237c673c07f9d827129ba02720108816abde562Ted Kremenek 18545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 185517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 185617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation oploc, bool dead) 185717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 18581237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 18591237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1861ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 1863ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(SC, Empty), Opc(MulAssign) { } 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 1873ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 1874ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 1877ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 1878ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 187917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 188017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 1881ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 1882ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 18845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 18855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1887ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 1888ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 1889ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 1890ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1891ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 1892ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 1893ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 1894ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 1895ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 1896ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1897ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 1898ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 1899ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 19011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 19075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 19101237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 19115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 191247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 19135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 191447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 191547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation CLoc, Expr *rhs, QualType t) 1916898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 1917898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 1918898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 1919898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 1920898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 19211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 1922898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 192347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 192447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 192547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 19261237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 19271237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 19281237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 19291237c673c07f9d827129ba02720108816abde562Ted Kremenek } 19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1931ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 1932ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 1933ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 1934ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1935395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 1936395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 19375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 1938ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 1939395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1940395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1941395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 1942395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 1943395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 1944395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 19451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // is only evaluated once. 1946395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 19475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 1948395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 19491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1950395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1951395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 19525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 1955ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1956ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 19575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1958ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 19595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 196047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 196147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 196247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 196347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 196447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 196547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 19675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 19685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19741237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 19751237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 19761237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19796481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 19806481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19846481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 19856481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 19866481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19887d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 19891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 19907d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 19917d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 19927d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 19937d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 19947d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 19957d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 19967d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 20027d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 20037d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 20045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 20051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 20065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20076481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20091237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20101237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20111237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 20125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2013ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2014ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2015ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2016ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2017ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 20185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2019ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2020ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 2021d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2022d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2023d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 20241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20256a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 20266a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 20276a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 20295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 20306a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 20316a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2032ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2033ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2034ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 20351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2036026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 20376a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2038026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 20396a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2041ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2043ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2044ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20461237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20471237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20481237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2049ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2050ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2051dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2052d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2053d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2054d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2055d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 2056d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 2057d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 2058363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2059d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType t1, QualType t2, SourceLocation RP) : 2062d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 2063363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff BuiltinLoc(BLoc), RParenLoc(RP) {} 2064d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 206544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 206644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 206744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 206844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 20697f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 207044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType1(QualType T) { Type1 = T; } 20717f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 207244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType2(QualType T) { Type2 = T; } 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 207544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 207844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 20791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2080d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2081363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2082d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2083d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 20841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2085d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2086d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20881237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20891237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20901237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2091d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2092d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2093d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2094d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2095d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2096d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2097d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2098d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2099d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2100d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2101d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2102d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2103d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2104d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2105d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 21065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2107d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2108d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2109888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected: 21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 2111888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2112d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 2113a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 2116d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc), 2117f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek RParenLoc(RP), NumExprs(nexpr) { 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2119a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2120d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2121d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2122d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 212394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 212494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 212694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 212794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 212894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 212994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 213194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 213294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 213394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2134d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2135d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2136d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2137d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 21381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2139d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2140d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 21411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2142888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman ~ShuffleVectorExpr() {} 21431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2144d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2145d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2146d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2147d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2149d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2150d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2151d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 21525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2153d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2154d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2155d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 21565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2157d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2159888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 216094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2161dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2162dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 21639a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2164d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2166d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2167d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2168d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2169d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2170d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2171d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 21721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2173d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 21747976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 21757976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 21767976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 21777976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 21787976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 21797976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2180d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 21811237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 21825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2183d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2184d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2185d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2186ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2187ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 21881237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 21891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 21901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 21911237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 21937976932a1c256d447316ffac58e9821417725e34Eli Friedman 219444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 219544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 219644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 21977976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 21987976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 219927437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 22007976932a1c256d447316ffac58e9821417725e34Eli Friedman 22017976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 22027976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 22037976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 22047976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 22057976932a1c256d447316ffac58e9821417725e34Eli Friedman } 22067976932a1c256d447316ffac58e9821417725e34Eli Friedman 22075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 220844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 22095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 221044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 22115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 221244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 221344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 221444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 221544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 221744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 221844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 22191237c673c07f9d827129ba02720108816abde562Ted Kremenek 2220d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2221d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2222d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2223d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 22241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2225d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2226d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22281237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 22291237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 22301237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2231d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2232d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 22332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 22342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 22352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 22362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 22372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 22382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 22392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 22402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 22412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 22422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 22432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 22441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 22452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { } 22462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 224744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 224844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 224944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 22502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 22512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 225244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 22532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 22542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 22552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 22562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 22572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 22592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 22602d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 22611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 22632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 22642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 22652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 22662d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 22677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start. 22687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 22695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 22707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 22717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 22727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 22737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson : Expr(VAArgExprClass, t), 22747c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 22757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 22767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 22771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2278d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Create an empty __builtin_va_start expression. 2279d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2280d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 22815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 22825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2283d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2284d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2285d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2286d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2288d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2289d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2290d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 22917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 22927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 22947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 22957c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 22967c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 22977c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 23007c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 23011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 23027c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 23054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 23064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 23074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 23084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 23094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 23104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 23114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 23124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2313196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 23144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 23154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 23164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 23174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 23184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 23194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 23204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 23214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2322196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 23234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 23244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 23254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 23264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 23274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 23284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 23294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 23303498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 23314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 23324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 23334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2334196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 23354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 23364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 23374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 23384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 23394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 23404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 234166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 234241ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor // FIXME: Eliminate this vector in favor of ASTContext allocation 23435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek std::vector<Stmt *> InitExprs; 234466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 23474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 23484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 23494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 23500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 23510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 23520bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 23530bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2354a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2355a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2356a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2357a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 235866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 235966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 23604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc); 2361d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2362d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2363d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { } 23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2365c5ae899b4bbf65488445316c63168079177db0edSteve Naroff unsigned getNumInits() const { return InitExprs.size(); } 23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getInit(unsigned Init) const { 2368c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 23694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 237066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 23711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getInit(unsigned Init) { 2373c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 23744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 237566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2378c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 23799e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 23809e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2381c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2382fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2383fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor void reserveInits(unsigned NumInits); 23841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 23864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 23874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 23884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 23894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 23904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 23914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 23924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 23934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 23944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 23954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 23964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 23974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 23984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 23994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 24004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *updateInit(unsigned Init, Expr *expr); 2401c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 24020bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 24030bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 24040bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 24050bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 24060bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 24070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 24080bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 24090bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 24100bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2411c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2412c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2413b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2414b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2415b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 24161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2417d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2418d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2419d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 242087fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 242187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 24224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 24234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 24244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 24264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 24274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 24284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2429a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 2431d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 2432a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 2433a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 243466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 243566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 24361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 243766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 243966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 244066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 244366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 244466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24467fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::iterator iterator; 24477fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::reverse_iterator reverse_iterator; 24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24497fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator begin() { return InitExprs.begin(); } 24507fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator end() { return InitExprs.end(); } 24517fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 24527fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rend() { return InitExprs.rend(); } 245366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 245466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 245505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 245605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 245705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 245805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 245905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 246005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 246105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 246305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 246405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 246505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 246605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 246705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 246805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 246905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 247005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 247105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 247205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 247305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 247405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 247505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 2476ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 2477ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 2478ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 2479ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2480ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 248105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 248205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 248305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 248405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2485eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 248605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 2487eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 248805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 248905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 249005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 249105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2492ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 2493ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 2494ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 2495ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 249605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 249705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 249805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 249905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 250005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2501ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 2503ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 2504eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 25059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 25069ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 250705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2508d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 2509d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 2510d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 2511d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 251242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected: 25131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void DoDestroy(ASTContext &C); 251442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 251505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 251605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 251705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 251805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 251905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 252005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 252105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 252205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 252305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 252405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 25251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 252605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 252705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 25281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 252905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 253005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 253105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 253205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 253305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 253405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 253505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 253605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 253705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 253805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 253905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 254005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 254105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 254205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 254305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 25441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 254505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 254605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 254705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 254805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 254905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 255005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 255105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 255205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 255305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 255405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 255505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 255605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 255705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 255805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 255905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 256005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 256105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 256205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 256305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 256405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 256505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 256605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 256705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 256805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 256905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 2570ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 2571ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 257205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 25731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 257505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 257605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 257705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 257805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 257905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 258005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 258105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 258305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 258405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 258505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 258605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 258705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 258805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 258905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 259005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 259105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 259305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 259405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 259505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 259605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 259705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 259805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 259905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 260005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 260105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 260205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 260305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 260405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 260505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 260605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 260705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 260805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 260905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 261005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 261105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 261205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 261305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 261405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 261505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 261605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 261705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 261805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 261905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 262087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 262187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 262287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 262387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 262487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 262505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 262605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 262705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 262805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 262905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 263005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 263105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 263205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 263305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 263405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 263505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 263605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 263705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 263805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 263905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 264005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 264105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 264205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 264305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 264405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 264505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 264605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 26474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2648d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 2649d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 2650d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 2651d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 2652d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2653d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 26544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 26554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 26564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 26574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 26584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 26594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 266005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 266105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 26621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 266305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 266405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 266505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 2666eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 266705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2668d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 2669d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 267005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 267105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 267205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 267305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 267405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 2675ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 2678ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 267905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2680711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 2681711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 2682d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setDesignators(const Designator *Desigs, unsigned NumDesigs); 2683d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 268405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 268505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 268605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 268705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 268805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 268905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 269005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 2691d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 269205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 269305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 2694eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 2695eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 2696d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 269705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 269805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 26991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 270005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 270105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 270205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 270305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 270405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 270505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 270605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2707d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 2708d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 2709d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 2710d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 2711d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 2712d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2713d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 2714d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2715d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2716d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2717d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 2718d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2719d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2720d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 2721d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2722d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2723d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2724d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 2725d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2726d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2727ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 2728ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void ExpandDesignator(unsigned Idx, const Designator *First, 2730ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 2731ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 273205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 273305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 273405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 273605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 273705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 273805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 273905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 274005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 27423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 27433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 27443498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 27453498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 27463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 27471a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 27481a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 27493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 27501a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 27511a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 27533498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 27541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 27553498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor : Expr(ImplicitValueInitExprClass, ty) { } 27563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 2757d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 2758d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 2759d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 2760d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 27611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27623498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 27633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 27643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 27653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 27663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 27673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 27683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 27693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 27703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 27713498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 27721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 277305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 277405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 27752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 27762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 27772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 27782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 27792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 27802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 27811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected: 27822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual void DoDestroy(ASTContext& C); 27831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 27851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 27862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 27872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 27882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman ~ParenListExpr() {} 27892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 27902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 27912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 27941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 27962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 27972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 27982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 27991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 28012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 28022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 28032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 28042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 280583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 28061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 28082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 28092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 28112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 28121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 28152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 28162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 28171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 28192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 28202ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 28212ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 28222ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 28254eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 28264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 28274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2828a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2829a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 2830a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 2831a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 2832a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 283373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 283473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 283573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 2836a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 2837a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 2838d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 2839a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 2840a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 2841a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 2842a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 28431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(ExtVectorElementExprClass, ty), 2844d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 28451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2846d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 2847d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 2848d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 2849d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2850a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 2851a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 2852d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 2853d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2854d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 2855d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 2856d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2857d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 2858d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 2859d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2860a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 2861a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 28621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2863a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 2864a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 2865a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2867a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 2868a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 2869a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2871a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 2872a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 2873a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 28741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28752140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 28762140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 28772140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 2881a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2882a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 28831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2884a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 2885a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 2886a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 2887a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 2888a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2889a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 289056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 28919c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 28924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 289356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 289456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 2895b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 28964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 2897b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 28981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(BlockExprClass, ty), 2899b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 29009c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 290184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 290284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 290384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 2904d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 290556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 290684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 290784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 290856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 290956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 291056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 291156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 29129c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 29139c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 291456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 29159c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 29169c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 291756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 291856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 291956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 2920b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 29215b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 2922b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 292384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 2924b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 29251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29269c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 29274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 29284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 29291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 29314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 29324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 29334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 29341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 29364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 29374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 29394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 29407d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 29417d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 29424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 29431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 29447d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool constAdded = false) : 29457d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef), 29467d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian ConstQualAdded(constAdded) {} 294794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 294894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 294994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 295094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 295194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 29544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 295594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 295694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 295794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 295894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 295994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 29604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 29611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 296394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 29641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29657d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 29667d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 296794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 29681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 29704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 29714eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 29721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 29744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 29754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 29764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 29774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 29785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 29795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2981