Expr.h revision ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8
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" 23c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 26590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 27c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 28c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 29c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 318e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 3488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 3588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 3688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 43898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected: 45898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// TypeDependent - Whether this expression is type-dependent 46898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// ValueDependent - Whether this expression is value-dependent 50898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 52898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor should go away and we should 54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // require every subclass to provide type/value-dependence 55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // information. 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T) 57b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(false), ValueDependent(false) { 5883233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor setType(T); 5983233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor } 60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(StmtClass SC, QualType T, bool TD, bool VD) 62b3eef68111ffc220e449be96da1747998c057790Douglas Gregor : Stmt(SC), TypeDependent(TD), ValueDependent(VD) { 63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 660b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 69f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregorpublic: 70f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 71f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor void setType(QualType t) { 729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 79f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor assert((TR.isNull() || !TR->isReferenceType()) && 808320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 81f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 82f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor TR = t; 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 85898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 86898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 87898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent. 89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValueDependent(bool VD) { ValueDependent = VD; } 960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<typename T> 104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1100b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setTypeDependent(bool TD) { TypeDependent = TD; } 1120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 122026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 123026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 124026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 125026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 12740b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis SourceRange &R2) const; 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 13808ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 13976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl /// - b ? x : y, where x and y are lvalues of suitable types [C++] 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 145fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 14686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 14786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_MemberFunction 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 14928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 15053202857c60214d80950a975e6e52aebf30bd16aEli Friedman 15153202857c60214d80950a975e6e52aebf30bd16aEli Friedman // Same as above, but excluding checks for non-object and void types in C 15253202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult isLvalueInternal(ASTContext &Ctx) const; 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and if it is a structure or union, does not have any member (including, 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 15944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 16044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 16144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 16244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 167fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 169ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1724f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1735daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 174ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 17586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 17686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_MemberFunction 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 17844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 17944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 18233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 18333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 18638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 18738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 18838d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 193590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 194590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 196590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 1978070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 198590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 200c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 201c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 202c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 20594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 2062d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 21894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 21994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 22194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 22294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 22394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 22494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 22594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 22694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 22794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2286ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 229019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 230019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 231019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2325b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2335b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 2346ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 23545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 23645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 237c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 23851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 23951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 24051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 24151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 2421b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue. 2431b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 2441b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 245efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 246efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 247efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 248efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson bool isNullPointerConstant(ASTContext &Ctx) const; 249efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 2502e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek /// hasGlobalStorage - Return true if this expression has static storage 2514cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// duration. This means that the address of this expression is a link-time 2524cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// constant. 2532e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek bool hasGlobalStorage() const; 25444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian 25544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 25644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// write barrier. 257102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 2584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 2594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 2604e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// its subexpression. If that subexpression is also a ParenExpr, 2614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 2624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 2634e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* IgnoreParens(); 26456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 26556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 26627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 26756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 2684e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 269ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 270ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 271ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 272ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 273ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 2744e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek const Expr* IgnoreParens() const { 2754e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 2764e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 27756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 27856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 27956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 280ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 281ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 282ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 283ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 285898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 286898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getStmtClass() <= lastExprConstant; 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 2955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 3028e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *D; 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3049e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 3059e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 3061a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // FIXME: Eventually, this constructor will go away and all subclasses 3071a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // will have to provide the type- and value-dependent flags. 3088e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) : 3099e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis Expr(SC, t), D(d), Loc(l) {} 3109e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 3111a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD, 3121a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor bool VD) : 3131a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor Expr(SC, t, TD, VD), D(d), Loc(l) {} 3141a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor will go away and all clients 317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // will have to provide the type- and value-dependent flags. 3188e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) : 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr(DeclRefExprClass, t), D(d), Loc(l) {} 320898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 321898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) : 322898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {} 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty declaration reference expression. 3250b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit DeclRefExpr(EmptyShell Empty) 3260b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(DeclRefExprClass, Empty) { } 3270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 3288e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *getDecl() { return D; } 3298e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor const NamedDecl *getDecl() const { return D; } 330904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor void setDecl(NamedDecl *NewD) { D = NewD; } 331904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 3329e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 3330b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 3379e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis return T->getStmtClass() == DeclRefExprClass || 3381a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == CXXConditionDeclExprClass || 3391a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == QualifiedDeclRefExprClass; 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 34277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 34377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 34477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 34577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 348d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 349d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 350227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 351227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 352227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 353227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 354cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor PrettyFunction 355227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 356227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 357227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 358227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 359227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 360227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 361d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 362d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {} 363227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 36417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 36517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor explicit PredefinedExpr(EmptyShell Empty) 36617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 36717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 3688b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl PredefinedExpr* Clone(ASTContext &C) const; 3698b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 370227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 37117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 37217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 37317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 37417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 37517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 376b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner // FIXME: The logic for computing the value of a predefined expr should go 377b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner // into a method here that takes the inner-most code decl (a block, function 378b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner // or objc method) that the expr lives in. This would allow sema and codegen 379b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner // to be consistent for things like sizeof(__func__) etc. 380b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner 381227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 382227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 383227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson static bool classof(const Stmt *T) { 384d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner return T->getStmtClass() == PredefinedExprClass; 385227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 386d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 38777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 38877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 38977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 39077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 391227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 392227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 403a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 4040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 4050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit IntegerLiteral(EmptyShell Empty) 4060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 4070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 408a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson IntegerLiteral* Clone(ASTContext &C) const; 409a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 413313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 414313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 415313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 4160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 4170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 4180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == IntegerLiteralClass; 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 42377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 42477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 42577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 42677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 432c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 435c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 436c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) { 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 4400b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 4410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4428b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl CharacterLiteral* Clone(ASTContext &C) const; 4438b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 4442eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner SourceLocation getLoc() const { return Loc; } 445c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 4462eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 4520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 4530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 4540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == CharacterLiteralClass; 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 45977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 46077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 46177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 46277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 466525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 467720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 470001d64dd2947c1ce06e3eac257a9a21c65ae4ff3Chris Lattner FloatingLiteral(const llvm::APFloat &V, bool isexact, 471720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 472001d64dd2947c1ce06e3eac257a9a21c65ae4ff3Chris Lattner : Expr(FloatingLiteralClass, Type), Value(V), IsExact(isexact), Loc(L) {} 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 47417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 4758b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl explicit FloatingLiteral(EmptyShell Empty) 47617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 47717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 4788b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl FloatingLiteral* Clone(ASTContext &C) const; 4798b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 480c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 48117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setValue(const llvm::APFloat &Val) { Value = Val; } 48217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 483720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 48417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 485c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 486da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 487da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 488da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 489da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 490da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 49117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 49217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 49317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 4944863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // FIXME: The logic for computing the value of a predefined expr should go 4954863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // into a method here that takes the inner-most code decl (a block, function 4964863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // or objc method) that the expr lives in. This would allow sema and codegen 4974863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner // to be consistent for things like sizeof(__func__) etc. 4984863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == FloatingLiteralClass; 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 50577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 50677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 50777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 50877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 5125d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 5135d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 5145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 5155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 5165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 5175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 5185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 5195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 5205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 5215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 522cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 523cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ImaginaryLiteral(EmptyShell Empty) 524cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 525cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 5265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 5275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 528cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 529cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 530d8ac436c8c10c52c937ba323db582259ceb06197Douglas Gregor ImaginaryLiteral* Clone(ASTContext &C) const; 531d8ac436c8c10c52c937ba323db582259ceb06197Douglas Gregor 5325d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 5335d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const Stmt *T) { 5345d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner return T->getStmtClass() == ImaginaryLiteralClass; 5355d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 5365d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 5375d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 5385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 5395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 5405d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 5415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 5425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 543e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 544e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 545e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 546a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 547c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 548c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 549690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 550690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 5518bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 552690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 553c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 554c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 555c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 556c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 557c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 558c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 563726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 564726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 5652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {} 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 5692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 5702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 572a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 5732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 5752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5762085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 5772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 5782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 5792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 580a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 581673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 582673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 583673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 584a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson StringLiteral* Clone(ASTContext &C) const; 585726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner void Destroy(ASTContext &C); 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 589673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 590673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 591673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setStrData(ASTContext &C, const char *Str, unsigned Len); 592673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 594673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 595673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 5968d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 59733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff for (unsigned i = 0; i < getByteLength(); ++i) 5988d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff if (!isascii(getStrData()[i]) || !getStrData()[i]) 59933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 60033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 60133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 602726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 603726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 604726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 605726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 606726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 607726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 608726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 609726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 610673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 611673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 612673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 613673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 614673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 615b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 616b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 617b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 620726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == StringLiteralClass; 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 62677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 62777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 62877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 62977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 6365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 639898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 640898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor val->isTypeDependent(), val->isValueDependent()), 641898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 643c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 644c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor explicit ParenExpr(EmptyShell Empty) 645c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 646c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 6475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 6485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 649c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 650c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 651866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 653313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 654313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 655c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 656313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 657313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 658313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 659c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 660313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ParenExprClass; 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 66577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 66677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 66777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 66877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 6730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 675dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 676dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 677dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 678dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 679dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 680dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 681dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 68273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 68373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// subexpression is a compound literal with the various MemberExpr and 68473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 68573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 68813d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 69673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 69773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 7005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 7069103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 7079103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 7089103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isValueDependent()), 7099103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 7120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit UnaryOperator(EmptyShell Empty) 7130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 7140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 7160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 7170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 7185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 7190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 7200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 7230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 7240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 7262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 7272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 7282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7305a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 7312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 7322085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 7332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 7345a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 7355a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 7375d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 7395a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 746bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 747bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 748bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 749bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 750bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 751bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 752bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 753bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == UnaryOperatorClass; 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 76677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 76777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 76877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 76977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 7730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 7740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 7750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 7760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 777d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 778d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl void *Ty; 779d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 780d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 783ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, QualType T, 7840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 7850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 7862850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 787ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 7882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 789ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor T->isDependentType()), 790ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 791ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ty = T.getAsOpaquePtr(); 792ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 793ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 794ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, Expr *E, 795ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 796ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 797ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 798ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 799ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 800ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 801ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 802ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 803d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 8040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 8050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 8060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 8070b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 8080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 8099048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar virtual void Destroy(ASTContext& C); 8109048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 8120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 8130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 8140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 8150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 8160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 817d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return QualType::getFromOpaquePtr(Argument.Ty); 8180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 819caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 8200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 821d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 8220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 823caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 824caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 825caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 8260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 8270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 8280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(QualType T) { 8290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor Argument.Ty = T.getAsOpaquePtr(); 8300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor isType = true; 8310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 8320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 8330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 8340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 8350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 8360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 8370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 8380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 83976e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 8400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 8410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 8420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 8430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 844866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 845866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 846866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 847866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 8500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return T->getStmtClass() == SizeOfAlignOfExprClass; 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 85377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 85477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 85577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 85677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 86577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 8665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 87073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 8712850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 8722850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 8732850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 8742850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 87573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 87673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 87773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 879cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 880cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 881cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 882cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 8832324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 8842324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 8852324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 8862324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 8872324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 88833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 88933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 89033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 89133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 8925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 8935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 894cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 895cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 8965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 8975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 898cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 8992324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 90077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getBase() { 9015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 90277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 90377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 9042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek const Expr *getBase() const { 9055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 9062324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 9072324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 90877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getIdx() { 9095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 9102324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 9112324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 91277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 9135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 91477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 916866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 91777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 919866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 920026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 921cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 922cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 9235cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ArraySubscriptExprClass; 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 92977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 93077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 93177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 93277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 936b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 937b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 938b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 939b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is 940b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 941b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 94377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 9445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 947d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 948b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 949b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 950668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 951668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 952d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 954668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 956668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 9571f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 958ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 9591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 960668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 961668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 962668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek void Destroy(ASTContext& C); 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 9655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 96618b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 9755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 9795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 981668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 982934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 983934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 984934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 985934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 986934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 987d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 988d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 989d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 990d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 9918189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 992d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 9935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 9945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 9955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 996d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 997d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 9985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 9995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 1000d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1005cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1006cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 10073c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 1008cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 10096dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// getCallReturnType - Get the return type of the call expr. This is not 10106dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// always the type of the expr itself, if the return type is a reference 10116dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 10126dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 10136dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson 1014d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 10151f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1016866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1017866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 101877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 1022b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 102388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 102488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXMemberCallExprClass; 10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 102788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 102888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 102988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 103077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 103177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 103277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1035ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 1038ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1039ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 10405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 1041ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 1042ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1043ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 104486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *MemberDecl; 1045ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 1046ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 1048ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 1049ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 1050ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner bool IsArrow; 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 105286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l, 1053510190777c4bd53e960eea4665b204778fec1b64Eli Friedman QualType ty) 1054ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson : Expr(MemberExprClass, ty, 1055ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {} 1057510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 10581f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty member reference expression. 10591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor explicit MemberExpr(EmptyShell Empty) : Expr(MemberExprClass, Empty) { } 10601f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 106188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 10625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 106357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 106457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 106557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 106657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 106757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 106886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *getMemberDecl() const { return MemberDecl; } 106988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setMemberDecl(NamedDecl *D) { MemberDecl = D; } 10701f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 10721f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 10731f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1074ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1075ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1076026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 10771f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 108072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 108172527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 108272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 108372527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 108472527137c521ad9330ecb81ccd841159719dc8cdEli Friedman return SourceRange(MemberLoc, MemberLoc); 108572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman return SourceRange(BaseLoc, MemberLoc); 10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1087866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == MemberExprClass; 10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 10941237c673c07f9d827129ba02720108816abde562Ted Kremenek 10951237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 10961237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 10971237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1100aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5] 1101aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1102aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 11030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 11040fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 11050fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 11060fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 11075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1108e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1109aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 1110a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, 1111a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool fileScope) 1112a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), 1113a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner FileScope(fileScope) {} 1114aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 1115ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1116ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1117ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1118ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 11195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 11205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1121ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1122e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1123e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1124ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1125ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 11260fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1127ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1128ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 112973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 11300fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 11310fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 11320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 11330fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 113473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 11350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 113673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1137aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 1138aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const Stmt *T) { 1139aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff return T->getStmtClass() == CompoundLiteralExprClass; 1140aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1141aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 11421237c673c07f9d827129ba02720108816abde562Ted Kremenek 11431237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 11441237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 11451237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1146aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1147aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 114849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 114949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 115049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 115149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 11520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 11530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 11540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 11550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis CastExpr(StmtClass SC, QualType ty, Expr *op) : 1156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1157898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1158898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1159898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1161898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 1162898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType() || (op && op->isValueDependent())), 1163898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Op(op) {} 11640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 1165087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 1166087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor CastExpr(StmtClass SC, EmptyShell Empty) 1167087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : Expr(SC, Empty) { } 1168087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 11690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 11700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 11710835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 1172087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 1173087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 11740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const Stmt *T) { 11759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 11769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 11779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 11789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 11796eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 11800835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 11819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 11829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 11830835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 11840835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 11850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 11860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 11870835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 11880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 11890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 11900835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 119149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 119249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 119349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 119449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 119549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1196bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1197bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1198bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1199bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1200bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1201bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1202bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 1203bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) { 1204bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1205bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1206bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 12070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1208eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1209eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1210eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 121149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 1212eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) : 1213b3eef68111ffc220e449be96da1747998c057790Douglas Gregor CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { } 121490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1215087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 1216087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor explicit ImplicitCastExpr(EmptyShell Shell) 1217087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor : CastExpr(ImplicitCastExprClass, Shell) { } 1218087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 1219087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 12200835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 12210835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 12220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 122390045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1224eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1225eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1226eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1227eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1228eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1229eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 123049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const Stmt *T) { 123149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff return T->getStmtClass() == ImplicitCastExprClass; 123249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 123349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 123449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 123549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 123649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 123749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code. 123849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 123949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 124049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 124149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 124249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 124349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 124549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 124649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 124749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 124849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 124949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 125049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 125149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 12520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 125349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// TypeAsWritten - The type that this expression is casting to, as 125449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// written in the source code. 125549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType TypeAsWritten; 125649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 125749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 12588320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy) 12598320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {} 126049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 1261db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 1262db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor ExplicitCastExpr(StmtClass SC, EmptyShell Shell) 1263db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : CastExpr(SC, Shell) { } 1264db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 126549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 126649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 126749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 126849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType getTypeAsWritten() const { return TypeAsWritten; } 1269db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setTypeAsWritten(QualType T) { TypeAsWritten = T; } 127049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 127149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const Stmt *T) { 12729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 12736eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass) 12749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 12759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 127649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 12779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 12789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 127949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 128049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 128149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 128249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 12836eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 128449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 128549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 12866eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1287b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1288b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12906eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy, 1291b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation l, SourceLocation r) : 1292b2f9e516327310d95840d442416084508f80c183Steve Naroff ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), 1293b2f9e516327310d95840d442416084508f80c183Steve Naroff LPLoc(l), RPLoc(r) {} 129449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1295db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 1296db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor explicit CStyleCastExpr(EmptyShell Shell) 1297db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : ExplicitCastExpr(CStyleCastExprClass, Shell) { } 1298db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1299b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1300db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 1301db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 1302b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 1303db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 1304db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1306b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 13096eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor return T->getStmtClass() == CStyleCastExprClass; 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13143fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 13153fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 13163fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 13173fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 13183fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 13193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 13203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 13213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 13223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 13233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 13243fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 13253fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 13263fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 13273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 13283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 13293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 13303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 13313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 133603d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1337224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 135617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 135717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 13585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 135917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 136017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 136117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic: 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 136317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 136417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1365898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1366898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 1367898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent()), 1368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 13691237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 13701237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isCompoundAssignmentOp() && 13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1375db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 1376db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor explicit BinaryOperator(EmptyShell Empty) 1377db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 1378db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 137917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 1380db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 1381db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 1383db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 1384db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 13855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1386db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 13875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1388db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 1389db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1398063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1399063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1400063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1401063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1402063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1403063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1404063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1405063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftOp() const { return Opc == Shl || Opc == Shr; } 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 1411f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1412f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1413f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1414f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1415f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1416f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 1417f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1418f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1419f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1420f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1425eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner static bool classof(const Stmt *S) { 1426eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 1427eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner S->getStmtClass() == CompoundAssignOperatorClass; 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 14301237c673c07f9d827129ba02720108816abde562Ted Kremenek 14311237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14321237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14331237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 14341237c673c07f9d827129ba02720108816abde562Ted Kremenek 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 143617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 143717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation oploc, bool dead) 143817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 14391237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 14401237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1442ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1443ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor BinaryOperator(StmtClass SC, EmptyShell Empty) 1444ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(SC, Empty), Opc(MulAssign) { } 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 1454ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 1455ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 1458ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 1459ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 146017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 146117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 1462ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 1463ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isCompoundAssignmentOp() && 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1468ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 1469ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 1470ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 1471ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1472ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 1473ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 1474ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 1475ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 1476ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 1477ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1478ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 1479ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 1480ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *S) { 1483eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == CompoundAssignOperatorClass; 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 14911237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 14925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t) 1495898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 1496898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 1497898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 1498898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 1499898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 1500898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (cond->isValueDependent() || 1501898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 1502898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (rhs && rhs->isValueDependent()))) { 15031237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 15041237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 15051237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 15061237c673c07f9d827129ba02720108816abde562Ted Kremenek } 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1508ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 1509ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 1510ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 1511ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 1512395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 1513395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 15145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 1515ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 1516395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1517395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1518395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 1519395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 1520395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 1521395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 1522395a2abf0028968d85958610e393e067885dc14fTed Kremenek // is only evaluated once. 1523395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 15245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 1525395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 1526395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1527395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1528395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 15295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 1530395a2abf0028968d85958610e393e067885dc14fTed Kremenek 15315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 1532ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1533ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 15345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1535ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ConditionalOperatorClass; 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 15441237c673c07f9d827129ba02720108816abde562Ted Kremenek 15451237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15461237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15471237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15506481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 15516481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 15525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 15545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15556481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 15566481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 15576481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15597d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 15607d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor explicit AddrLabelExpr(EmptyShell Empty) 15617d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 15627d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 15637d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 15647d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 15657d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 15667d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 15677d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 15737d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 15747d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 15766481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner return T->getStmtClass() == AddrLabelExprClass; 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15786481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 15791237c673c07f9d827129ba02720108816abde562Ted Kremenek 15801237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15811237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15821237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1584ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1585ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 1586ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 1587ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 1588ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 15895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 1590ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 1591ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 1592d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 1593d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 1594d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 1595ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 15966a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 15976a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 15986a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 15995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 16005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 16016a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 16026a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 1603ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 1604ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 1605ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1607026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 16086a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1609026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 16106a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1611026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 1612ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 1613ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return T->getStmtClass() == StmtExprClass; 1614ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 1615ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 16161237c673c07f9d827129ba02720108816abde562Ted Kremenek 16171237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 16181237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 16191237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1620ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 1621ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1622dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 1623d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 1624d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 1625d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 1626d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 1627d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 1628d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 1629363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1630d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 1631363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 1632d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType t1, QualType t2, SourceLocation RP) : 1633d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 1634363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff BuiltinLoc(BLoc), RParenLoc(RP) {} 1635d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 163644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 163744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 163844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 163944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 16407f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 164144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType1(QualType T) { Type1 = T; } 16427f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 164344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setArgType2(QualType T) { Type2 = T; } 1644ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff 164544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 164644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 164744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 164844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 164944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 165044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 1651d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 1652363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1653d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1654d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 1655d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff return T->getStmtClass() == TypesCompatibleExprClass; 1656d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1657d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 16581237c673c07f9d827129ba02720108816abde562Ted Kremenek 16591237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 16601237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 16611237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1662d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 1663d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 1664d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 1665d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 1666d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 1667d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 1668d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 1669d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 1670d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 1671d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 1672d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1673d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 1674d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 1675d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 1676d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 16775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 1678d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 1679d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1680d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 1681d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ShuffleVectorExpr(Expr **args, unsigned nexpr, 1682d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman QualType Type, SourceLocation BLoc, 1683d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation RP) : 1684d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc), 1685f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek RParenLoc(RP), NumExprs(nexpr) { 1686f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek 16875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[nexpr]; 1688d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 1689d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 1690d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 169194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 169294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 169394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit ShuffleVectorExpr(EmptyShell Empty) 169494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 169594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 169694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 169794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 169894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 169994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 170094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 170194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 1702d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 1703d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 1704d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 1706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return T->getStmtClass() == ShuffleVectorExprClass; 1707d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 1709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1710d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ~ShuffleVectorExpr() { 1711d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman delete [] SubExprs; 1712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1714d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 1715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 1716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 1717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 1718d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 1720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 1721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 17225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1723d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1724d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 1725d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 17265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1727d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1728d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 172994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setExprs(Expr ** Exprs, unsigned NumExprs); 173094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 1731dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 1732dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 17339a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 1734d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1735d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1736d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 1737d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 1738d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 1739d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 1740d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1741d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 1742d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with 1743d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 17447976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 17457976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 17467976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 17477976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 17487976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 17497976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 1750d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 17511237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 17525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 1753d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1754d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 1755d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 1756d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation RP) 1757d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff : Expr(ChooseExprClass, t), 17581237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 17591237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 17601237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 17611237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 17621237c673c07f9d827129ba02720108816abde562Ted Kremenek } 17637976932a1c256d447316ffac58e9821417725e34Eli Friedman 176444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 176544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 176644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 17677976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 17687976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 176927437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 17707976932a1c256d447316ffac58e9821417725e34Eli Friedman 17717976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 17727976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 17737976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 17747976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 17757976932a1c256d447316ffac58e9821417725e34Eli Friedman } 17767976932a1c256d447316ffac58e9821417725e34Eli Friedman 17775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 177844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 17795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 178044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 17815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 178244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 178344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 178444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 178544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 178644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 178744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 178844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 17891237c673c07f9d827129ba02720108816abde562Ted Kremenek 1790d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 1791d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1792d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1793d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 1794d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return T->getStmtClass() == ChooseExprClass; 1795d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1796d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 17971237c673c07f9d827129ba02720108816abde562Ted Kremenek 17981237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 17991237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 18001237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1801d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 1802d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 18032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 18042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 18052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 18062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 18072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 18082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 18092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 18102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 18112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 18122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 18132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 18142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor GNUNullExpr(QualType Ty, SourceLocation Loc) 18152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { } 18162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 181744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 181844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 181944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 18208b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl GNUNullExpr* Clone(ASTContext &C) const; 18218b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 18222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 18232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 182444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 18252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 18262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 18272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 18282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 18292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 18302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return T->getStmtClass() == GNUNullExprClass; 18312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 18322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 18332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 18342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 18352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 18362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 18372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 18382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 18397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start. 18407c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 18415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 18427c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 18437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 18447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 18457c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson : Expr(VAArgExprClass, t), 18467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 18477c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 18487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 18497c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 1850d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Create an empty __builtin_va_start expression. 1851d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 1852d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 18535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 18545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1855d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1856d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 1857d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 1858d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 1859d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 1860d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 1861d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1862d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 18637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 18647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 18657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 18667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 18677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 18687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 18697c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 18707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 18717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 18727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 18737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_end(); 18747c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 18757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 18764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 18774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 18784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 18794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 18804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 18814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 18824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 18834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 18844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 1885196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 18864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 18874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 18884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 18894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 18904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 18914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 18924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 18934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 1894196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 18954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 18964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 18974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 18984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 18994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 19004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 19014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 19023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 19034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 19044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 19054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 1906196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 19074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 19084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 19094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 19104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 19114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 19124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 191366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 19145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek std::vector<Stmt *> InitExprs; 191566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 1916418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner 19174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 19184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 19194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 19204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 19210bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 19220bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 19230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 19240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1925a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 1926a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 1927a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 1928a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 192966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 193066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 19314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc); 1932d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 1933d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 1934d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { } 193566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 1936c5ae899b4bbf65488445316c63168079177db0edSteve Naroff unsigned getNumInits() const { return InitExprs.size(); } 193766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 193866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson const Expr* getInit(unsigned Init) const { 1939c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 19404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 194166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 194266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 194366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson Expr* getInit(unsigned Init) { 1944c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 19454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 194666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 194766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 19489e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff void setInit(unsigned Init, Expr *expr) { 1949c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 19509e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 19519e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 1952c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 1953fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 1954fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor void reserveInits(unsigned NumInits); 1955fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 19564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 19574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 19584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 19594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 19604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 19614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 19624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 19634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 19644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 19654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 19664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 19674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 19684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 19694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 19704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 19714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *updateInit(unsigned Init, Expr *expr); 1972c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 19730bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 19740bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 19750bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 19760bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 19770bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 19780bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 19790bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 19800bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 19810bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1982c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 1983c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 1984b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 1985b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 1986b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 19879e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff 1988d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 1989d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 1990d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 199187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 199287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 19934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 19944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 19954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 19964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 19974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 19984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 19994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2000a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 2001d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void sawArrayRangeDesignator(bool ARD = true) { 2002d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 2003a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 2004a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 200566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 200666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 200766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 200866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 200966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return T->getStmtClass() == InitListExprClass; 201066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 201166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 201266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 201366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 201466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 201566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 20166336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek 20177fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::iterator iterator; 20187fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::reverse_iterator reverse_iterator; 20197fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek 20207fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator begin() { return InitExprs.begin(); } 20217fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator end() { return InitExprs.end(); } 20227fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 20237fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rend() { return InitExprs.rend(); } 202466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 202566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 202705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 202905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 203005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 203105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 203205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 203305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 203405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 203905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 204005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 204105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 204205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 204605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 2047ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 2048ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 2049ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 2050ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 2051ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 205205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 205305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 205405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 205505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2056eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 205705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 2058eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 205905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 206005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 206105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 206205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2063ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 2064ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 2065ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 2066ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 206705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 206805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 206905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 207005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 207105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2072ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 207305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 2074ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 2075eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 20769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 20779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 207805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2079d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 2080d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 2081d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 2082d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 208305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 208405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 208505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 208605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 208705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 208805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 208905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 209005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 209105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 209205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 209305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 209405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 209505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 209605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 209705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 209805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 209905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 210005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 210105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 210205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 210305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 210405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 210505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 210605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 210705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 210805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 210905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 211005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 211105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 211205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned RBracketLoc; 211305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 211405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 211505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 211605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 211705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 211805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 211905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 212005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 212105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 212205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 212305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 212405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 212505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 212605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 212705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 212805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 212905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 213005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 213105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 213205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 213305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 213405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 213505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 213605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 213705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 2138ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 2139ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 214005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 214105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 214205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation FieldLoc) 214305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 214405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 214505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 214605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 214705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 214805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 214905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 215005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 215105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 215205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 215305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 215405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 215505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 215605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 215705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 215805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 215905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 216005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 216105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 216205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 216305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 216405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 216505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 216605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 216705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 216805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 216905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 217005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 217105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 217205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 217305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 217405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 217505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 217605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 217705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 217805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 217905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 218005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 218105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 218205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 218305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 218405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 218505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 218605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 218705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 218887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 218987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 219087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 219187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 219287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 219305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 219405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 219505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 219605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 219705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 219805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 219905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 220005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 220105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 220205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 220305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 220405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 220505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 220605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 220705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 220805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 220905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 221005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 221105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 221205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 221305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 221405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 22154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 2216d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 2217d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 2218d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 2219d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 2220d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2221d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 22224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 22234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 22244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 22254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 22264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 22274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 222805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 222905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 223005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 223105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 223205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 223305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 2234eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 223505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2236d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 2237d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 223805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 223905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 224005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 224105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 224205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 2243ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 2244ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_end() { 2245ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return Designators + NumDesignators; 2246ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 224705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2248711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 2249711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 2250d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setDesignators(const Designator *Desigs, unsigned NumDesigs); 2251d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 225205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 225305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 225405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 225505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 225605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 225705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 225805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 2259d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 226005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 226105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 2262eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 2263eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 2264d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 226505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 226605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 226705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getInit() const { 226805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 226905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 227005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 227105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 227205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 227305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 227405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2275d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 2276d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 2277d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 2278d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 2279d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 2280d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2281d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 2282d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2283d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2284d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2285d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 2286d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2287d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2288d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 2289d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 2290d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 2291d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 2292d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 2293d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 2294d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2295ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 2296ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 2297ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor void ExpandDesignator(unsigned Idx, const Designator *First, 2298ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 2299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 230005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 230105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2302ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor virtual void Destroy(ASTContext &C); 2303ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 230405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 230505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return T->getStmtClass() == DesignatedInitExprClass; 230605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 230705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 230805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 230905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 231005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 23113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_end(); 23123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 23133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 23143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 23153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 23163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 23171a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 23181a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 23193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 23201a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 23211a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 23223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr { 23233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 23243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor explicit ImplicitValueInitExpr(QualType ty) 23253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor : Expr(ImplicitValueInitExprClass, ty) { } 23263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 2327d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 2328d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 2329d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 2330d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 23313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const Stmt *T) { 23323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 23333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 23343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 23353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 23363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 23373498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 23383498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 23393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 23409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ImplicitValueInitExpr *Clone(ASTContext &C) const; 23419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 23433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 234405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_end(); 234505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 234605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 23474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 23484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 23494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 23504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2351a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2352a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 2353a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 2354a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 2355a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 235673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 235773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 235873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 2359a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 2360a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 2361d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 2362a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 2363a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 2364a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 2365a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 2366a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(ExtVectorElementExprClass, ty), 2367d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 2368a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2369d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 2370d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 2371d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 2372d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2373a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 2374a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 2375d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 2376d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2377d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 2378d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 2379d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2380d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 2381d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 2382d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 2383a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 2384a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 2385a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2386a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 2387a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 2388a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 2389a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2390a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 2391a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 2392a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 2393a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2394a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 2395a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 2396a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2397a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 23982140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 23992140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 24002140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 24012140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2402a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const Stmt *T) { 2403a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return T->getStmtClass() == ExtVectorElementExprClass; 2404a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2405a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 2406a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2407a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 2408a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 2409a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 2410a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 2411a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2412a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 241356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 24149c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 24154eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 241656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 241756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 2418b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 24194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 2420b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 2421b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump : Expr(BlockExprClass, ty), 2422b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 24239c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 242484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 242584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 242684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 2427d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 242856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 242984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 243084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 243156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 243256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 243356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 243456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 24359c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 24369c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 243756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 24389c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 24399c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 244056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 244156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 244256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 2443b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 24445b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 2445b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 244684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 2447b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 24484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 24499c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 24504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 24514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 24524eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 24534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 24544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 24554eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 24564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 24579c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 24584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 24594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 24604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 24614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *D; 24624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 24637d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 24647d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 24654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 24667d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 24677d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool constAdded = false) : 24687d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef), 24697d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian ConstQualAdded(constAdded) {} 247094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 247194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 247294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 247394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 247494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 24754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 24764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 24774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 247894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 247994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 248094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 248194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 248294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 24834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 24844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 24854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 248694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 24877d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian 24887d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 24897d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 249094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 24914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 24924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff return T->getStmtClass() == BlockDeclRefExprClass; 24934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 24944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 24954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 24964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 24974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 24984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 24994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 25004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 25025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2504