Expr.h revision 0b7489194f9f89fac39d57211c1e7953ae50251f
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 44898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// TypeDependent - Whether this expression is type-dependent 45898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.expr]). 46898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool TypeDependent : 1; 47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// ValueDependent - Whether this expression is value-dependent 49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.constexpr]). 50898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool ValueDependent : 1; 51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 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, 127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 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]] 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 144fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 14586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 14686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_MemberFunction 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 14828be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and if it is a structure or union, does not have any member (including, 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 159fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 161ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1644f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1655daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 166ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 16786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 16886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_MemberFunction 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 17028be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const; 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor bool isBitField(); 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 174cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// getIntegerConstantExprValue() - Return the value of an integer 175cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// constant expression. The expression must be a valid integer 176cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// constant expression as determined by isIntegerConstantExpr. 177cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const { 1788070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 179cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar bool success = isIntegerConstantExpr(X, Ctx); 180a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar success = success; 181cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar assert(success && "Illegal argument to getIntegerConstantExpr"); 182cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar return X; 183cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar } 184cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 189590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 190590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 1922d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx, 1932d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar SourceLocation *Loc = 0, 1942d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar bool isEvaluated = true) const; 195590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 1968070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 197590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 199c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 200c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 201c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 2052d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 20694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 21894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 21994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 22194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 22294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 22394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 22494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 22594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 22694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2276ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 228019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 229019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 230019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2315b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2325b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 2336ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 23445b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 23545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 236c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 23751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 23851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 23951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 24051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 2411b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue. 2421b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 2431b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 244efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 245efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 246efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 247efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson bool isNullPointerConstant(ASTContext &Ctx) const; 248efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 2492e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek /// hasGlobalStorage - Return true if this expression has static storage 2504cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// duration. This means that the address of this expression is a link-time 2514cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// constant. 2522e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek bool hasGlobalStorage() const; 25344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian 25444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 25544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// write barrier. 25644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian bool isOBJCGCCandidate() const; 2574e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 2584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 2594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// its subexpression. If that subexpression is also a ParenExpr, 2604e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 2614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 2624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* IgnoreParens(); 26356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 26456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 26527c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 26656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 2674e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 268ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 269ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 270ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 271ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 272ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 2734e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek const Expr* IgnoreParens() const { 2744e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 2754e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 27656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 27756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 27856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 279ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 280ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 281ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 282ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 283898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 285898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getStmtClass() <= lastExprConstant; 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 2912e7d352dbec06755105237afba183492d31d03cbTed Kremenek 292e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) { 293e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop return cast<Expr>(Stmt::Create(D, C)); 2942e7d352dbec06755105237afba183492d31d03cbTed Kremenek } 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 2985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 3058e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *D; 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3079e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 3089e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 3091a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // FIXME: Eventually, this constructor will go away and all subclasses 3101a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // will have to provide the type- and value-dependent flags. 3118e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) : 3129e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis Expr(SC, t), D(d), Loc(l) {} 3139e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 3141a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD, 3151a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor bool VD) : 3161a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor Expr(SC, t, TD, VD), D(d), Loc(l) {} 3171a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 319898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor will go away and all clients 320898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // will have to provide the type- and value-dependent flags. 3218e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) : 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr(DeclRefExprClass, t), D(d), Loc(l) {} 323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 324898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) : 325898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {} 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty declaration reference expression. 3280b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit DeclRefExpr(EmptyShell Empty) 3290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(DeclRefExprClass, Empty) { } 3300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 3318e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *getDecl() { return D; } 3328e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor const NamedDecl *getDecl() const { return D; } 333904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor void setDecl(NamedDecl *NewD) { D = NewD; } 334904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 3359e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 3360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 3409e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis return T->getStmtClass() == DeclRefExprClass || 3411a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == CXXConditionDeclExprClass || 3421a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == QualifiedDeclRefExprClass; 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 34577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 34677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 34777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 34877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3492dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 350ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 351e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 354d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 355d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 356227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 357227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 358227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 359227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 360cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor PrettyFunction 361227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 362227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 363227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 364227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 365227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 366227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 367d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 368d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {} 369227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 370227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 371227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 372227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 373227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 374227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson static bool classof(const Stmt *T) { 375d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner return T->getStmtClass() == PredefinedExprClass; 376227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 377d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 37877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 37977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 38077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 38177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3821ba485e582edfc8636afc25a6d7453c869530688Ted Kremenek 383ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 384d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 385227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 386227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 397a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 3980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty integer literal. 3990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit IntegerLiteral(EmptyShell Empty) 4000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor : Expr(IntegerLiteralClass, Empty) { } 4010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 402a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson IntegerLiteral* Clone(ASTContext &C) const; 403a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 407313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 408313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 409313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 4100b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(const llvm::APInt &Val) { Value = Val; } 4110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 4120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == IntegerLiteralClass; 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 41777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 41877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 41977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 42077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 4212dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 422ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 423e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 429c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 432c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 433c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) { 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4350b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 4370b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 4380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4392eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner SourceLocation getLoc() const { return Loc; } 440c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 4412eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 4470b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 4480b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 4490b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == CharacterLiteralClass; 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 45477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 45577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 45677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 45777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 4587338a8299ec393eaf6bb580b5ef9ab2b08b5bd11Ted Kremenek 459ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 460e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 464525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 465720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 468720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek FloatingLiteral(const llvm::APFloat &V, bool* isexact, 469720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 470720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {} 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 472c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 473720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek 474720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 475c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 476da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 477da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 478da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 479da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 480da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == FloatingLiteralClass; 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 48777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 48877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 48977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 49077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 491612c9b9ca73593b3194866c9e1a51554db9752e7Ted Kremenek 492ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 493e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 4975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 4985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 4995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 5005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 5015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 5025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 5035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 5045d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 5055d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 5065d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 5075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 5085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 5095d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 5105d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 5115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const Stmt *T) { 5125d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner return T->getStmtClass() == ImaginaryLiteralClass; 5135d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 5145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 5155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 5165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 5175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 5185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 5191c72de1be77fc43cc27e9bf1cbfe7bd25bee2f81Ted Kremenek 520ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 521e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 5225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 5235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 524e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 525e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 526e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 527a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 528c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 529c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 530690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 531690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 5328bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 533690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 534c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 535c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 536c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 537c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 538c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 539c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 544726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 545726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 5462085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {} 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 5502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 5512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 553a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 5542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 5562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 5582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 5592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 5602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 561a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 562a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson StringLiteral* Clone(ASTContext &C) const; 563726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner void Destroy(ASTContext &C); 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 5688d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 56933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff for (unsigned i = 0; i < getByteLength(); ++i) 5708d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff if (!isascii(getStrData()[i]) || !getStrData()[i]) 57133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 57233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 57333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 574726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 575726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 576726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 577726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 578726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 579726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 580726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 581726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 582b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner 583b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 584b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 585b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 588726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == StringLiteralClass; 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 59477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 59577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 59677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 59777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5987febad7377c04607aa2c744d58af61e1abea6250Ted Kremenek 599ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 600e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 6075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 610898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 611898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor val->isTypeDependent(), val->isValueDependent()), 612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 6155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 616866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 618313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 619313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 620313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 621313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 622313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 623313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ParenExprClass; 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 62877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 62977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 63077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 63177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6329eea2ca5f2cb5d77569274702b5b06273e426dc2Ted Kremenek 633ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 634e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 6390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 641dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 642dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 643dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 644dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 645dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 646dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 647dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 64873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 64973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// subexpression is a compound literal with the various MemberExpr and 65073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 65173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 65413d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 66273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 66373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 6665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 6729103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 6739103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 6749103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isValueDependent()), 6759103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 6785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 6842085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 6852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 6862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6885a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 6892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 6902085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 6912085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 6925a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 6935a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 6955d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 6975a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 704bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 705bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 706bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 707bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 708bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 709bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 710bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 711bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == UnaryOperatorClass; 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 72477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 72577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 72677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 72777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 7281049436d4b53d928b555f7381bc1639dd302bbc7Ted Kremenek 729ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 730e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 7340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 7350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 7360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 7370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 738d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 739d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl void *Ty; 740d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 741d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 744ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, QualType T, 7450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 7460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 7472850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 748ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 7492850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 750ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor T->isDependentType()), 751ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 752ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ty = T.getAsOpaquePtr(); 753ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 754ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 755ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, Expr *E, 756ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 757ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 758ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 759ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 760ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 761ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 762ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 763ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 764d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 7650518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 7669048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar virtual void Destroy(ASTContext& C); 7679048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 7690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 7700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 7710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 772d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return QualType::getFromOpaquePtr(Argument.Ty); 7730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 774caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 7750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 776d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 7770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 778caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 779caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 780caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 781caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner 7820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 7830518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 7840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 7850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 7860518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 7870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 78876e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 789866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 790866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 791866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 792866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 7950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return T->getStmtClass() == SizeOfAlignOfExprClass; 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 79877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 79977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 80077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 80177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 802ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek 803ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 8040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 81377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 8145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8172324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 81873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 8192850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 8202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 8212850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 8222850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 82373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 82473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 82573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8272324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 8282324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 8292324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 8302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 8312324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 83233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 83333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 83433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 83533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 8365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 8375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 83877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 8395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 8405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 8412324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 84277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getBase() { 8435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 84477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 84577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 8462324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek const Expr *getBase() const { 8475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 8482324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 8492324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 85077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getIdx() { 8515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 8522324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 8532324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 85477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 8555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 85677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 858866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 85977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 861866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 862026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 8635cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ArraySubscriptExprClass; 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 86977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 87077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 87177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 87277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 87396fa54fc6dc7f4c8dad1fb22fc7fc4f4d775d6c0Ted Kremenek 874ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 875e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 879b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 880b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 881b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 882b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is 883b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 884b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 88677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 8875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 890d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 891d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek // This version of the ctor is for deserialization. 892b4609806e9232593ece09ce08b630836e825865cDouglas Gregor CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t, 893d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek SourceLocation rparenloc) 894b4609806e9232593ece09ce08b630836e825865cDouglas Gregor : Expr(SC,t), SubExprs(subexprs), 895d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek NumArgs(numargs), RParenLoc(rparenloc) {} 896b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 897b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 898b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 899668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 900668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 901d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 903668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 905668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 906668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 907668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 908668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek void Destroy(ASTContext& C); 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 9115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 91218b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 9215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 9255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 927668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 928668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // FIXME: Why is this needed? Why not just create the CallExpr with the 929668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // corect number of arguments? It makes the ASTs less brittle. 930934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 931934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 932934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 933934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 934934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 935d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 936668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // FIXME: It would be great to just get rid of this. There is only one 937668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // callee of this method, and it probably could be refactored to not use 938668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // this method and instead just create a CallExpr with the right number of 939668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // arguments. 940d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 941d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 942d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 9438189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 944d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 9455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 9465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 9475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 948d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 949d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 9505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 9515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 952d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 957cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 958cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 9593c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 960cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 961d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 962866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 963866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 968b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 96988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 97088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXMemberCallExprClass; 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 97388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 97488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 97588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 97677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 97777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 97877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 979d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 980ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 981b4609806e9232593ece09ce08b630836e825865cDouglas Gregor static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C, 982b4609806e9232593ece09ce08b630836e825865cDouglas Gregor StmtClass SC); 9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 985ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 988ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 989ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 9905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 991ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 992ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 993ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 99486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *MemberDecl; 995ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 996ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 998ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 999ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 1000ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner bool IsArrow; 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 100286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l, 1003510190777c4bd53e960eea4665b204778fec1b64Eli Friedman QualType ty) 1004510190777c4bd53e960eea4665b204778fec1b64Eli Friedman : Expr(MemberExprClass, ty), 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {} 1006510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 100788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 10085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 100957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 101057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 101157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 101257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 101357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 101486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *getMemberDecl() const { return MemberDecl; } 101588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setMemberDecl(NamedDecl *D) { MemberDecl = D; } 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 1017ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 1018ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1019ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1020026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getBase()->getLocStart(), MemberLoc); 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1025866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == MemberExprClass; 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 10321237c673c07f9d827129ba02720108816abde562Ted Kremenek 10331237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 10341237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 10351237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1036bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek 1037bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1038e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1041aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5] 1042aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1043aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 10440fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 10450fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 10460fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 10470fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 10485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1049e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1050aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 1051a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, 1052a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool fileScope) 1053a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), 1054a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner FileScope(fileScope) {} 1055aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 10565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 10575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1058e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1059e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1060aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 10610fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 10620fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner 106373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 10640fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 10650fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 10660fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 10670fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 106873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 10690fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 107073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1071aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 1072aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const Stmt *T) { 1073aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff return T->getStmtClass() == CompoundLiteralExprClass; 1074aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1075aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 10761237c673c07f9d827129ba02720108816abde562Ted Kremenek 10771237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 10781237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 10791237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 10804b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek 10814b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1082e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1083aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1084aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 108549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 108649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 108749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 108849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 10890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 10900835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 10910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 10920835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis CastExpr(StmtClass SC, QualType ty, Expr *op) : 1093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1094898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1096898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1097898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1098898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 1099898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType() || (op && op->isValueDependent())), 1100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Op(op) {} 11010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 11020835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 11030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 11040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 11050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 11060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const Stmt *T) { 11079d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 11089d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 11099d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 11109d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 11116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 11120835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 11139d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 11149d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 11150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 11160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 11170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 11180835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 11190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 11200835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 11210835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 11220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 112349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 112449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 112549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 112649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 112749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1128bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1129bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1130bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1131bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1132bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1133bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1134bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 1135bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) { 1136bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1137bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1138bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 11390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1140eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1141eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1142eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 114349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 1144eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) : 1145b3eef68111ffc220e449be96da1747998c057790Douglas Gregor CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { } 114690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 11470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 11480835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 11490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 115090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1151eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1152eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1153eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1154eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1155eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1156eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 115749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const Stmt *T) { 115849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff return T->getStmtClass() == ImplicitCastExprClass; 115949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 116049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 11611237c673c07f9d827129ba02720108816abde562Ted Kremenek 1162ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1163e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 116449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 116549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 116649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 116749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code. 116849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 116949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 117049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 117149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 117249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 117349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 117549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 117649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 117749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 117849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 117949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 118049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 118149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 11820835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 118349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// TypeAsWritten - The type that this expression is casting to, as 118449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// written in the source code. 118549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType TypeAsWritten; 118649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 118749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 11888320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy) 11898320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {} 119049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 119149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 119249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 119349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 119449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType getTypeAsWritten() const { return TypeAsWritten; } 119549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 119649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const Stmt *T) { 11979d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 11986eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass) 11999d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 12009d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 120149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 12029d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 12039d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 120449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 120549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 120649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 120749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 12086eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 120949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 121049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 12116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1212b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1213b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12156eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy, 1216b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation l, SourceLocation r) : 1217b2f9e516327310d95840d442416084508f80c183Steve Naroff ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), 1218b2f9e516327310d95840d442416084508f80c183Steve Naroff LPLoc(l), RPLoc(r) {} 121949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1220b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1221b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1224b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 12276eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor return T->getStmtClass() == CStyleCastExprClass; 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12296eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 12309971c9ace70624987cd74645a75f4bfbc05afdf2Ted Kremenek 1231ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 12326eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 12363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 12373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 12383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 12393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 12403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 12413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 12423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 12433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 12443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 12453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 12463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 12473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 12483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 12493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 12503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 12513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 12523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 125703d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1258224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 127717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 127817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 12795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 128017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 128117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 128217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic: 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 128417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 128517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1286898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 1288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent()), 1289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 12901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 12911237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isCompoundAssignmentOp() && 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 129617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 12985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 12995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1308063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1309063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1310063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1311063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1312063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1313063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1314063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1315063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftOp() const { return Opc == Shl || Opc == Shr; } 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 1321f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1322f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1323f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1324f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1325f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1326f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 1327f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1328f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1329f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1330f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1335eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner static bool classof(const Stmt *S) { 1336eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 1337eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner S->getStmtClass() == CompoundAssignOperatorClass; 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 13401237c673c07f9d827129ba02720108816abde562Ted Kremenek 13411237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 13421237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 13431237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 13442dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 1345ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1346e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 13471237c673c07f9d827129ba02720108816abde562Ted Kremenek 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 134917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 135017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation oploc, bool dead) 135117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 13521237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 13531237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 1364ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 1365ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 1368ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ResType, QualType CompLHSType, 1369ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType CompResultType, 137017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 137117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 1372ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 1373ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isCompoundAssignmentOp() && 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1378ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 1379ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 1380ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 1381ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 1382ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *S) { 1386eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == CompoundAssignOperatorClass; 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 138883efb151a0c1df8cb8fb25d6dbb6c0f12f07f60aTed Kremenek 1389ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1390e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D, 1391e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop ASTContext& C); 13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 13981237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 13995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t) 1402898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 1403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 1404898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 1405898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 1406898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 1407898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (cond->isValueDependent() || 1408898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 1409898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (rhs && rhs->isValueDependent()))) { 14101237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 14111237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 14121237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 14131237c673c07f9d827129ba02720108816abde562Ted Kremenek } 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1415395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 1416395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 14175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 1418395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1419395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1420395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 1421395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 1422395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 1423395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 1424395a2abf0028968d85958610e393e067885dc14fTed Kremenek // is only evaluated once. 1425395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 14265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 1427395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 1428395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1429395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1430395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 14315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 1432395a2abf0028968d85958610e393e067885dc14fTed Kremenek 14335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 14345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ConditionalOperatorClass; 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 14431237c673c07f9d827129ba02720108816abde562Ted Kremenek 14441237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14451237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14461237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1447aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1448ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1449e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14526481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 14536481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14576481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 14586481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 14596481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 14686481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner return T->getStmtClass() == AddrLabelExprClass; 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14706481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 14711237c673c07f9d827129ba02720108816abde562Ted Kremenek 14721237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14731237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14741237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1475aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1476ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1477e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1479ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1480ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 1481ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 1482ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 1483ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 14845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 1485ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 1486ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 1487d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 1488d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 1489d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 1490ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 14915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 14925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 1493ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1494ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 1495ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 1496ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1498026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1499026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1500026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 1501ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 1502ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return T->getStmtClass() == StmtExprClass; 1503ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 1504ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 15051237c673c07f9d827129ba02720108816abde562Ted Kremenek 15061237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15071237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15081237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1509aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1510ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1511e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1512ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 1513ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1514d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p. 1515d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 1516d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 1517d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 1518d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 1519d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 1520d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 1521363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1522d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 1523363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 1524d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType t1, QualType t2, SourceLocation RP) : 1525d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 1526363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff BuiltinLoc(BLoc), RParenLoc(RP) {} 1527d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 15287f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 15297f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 1530ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff 1531d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 1532363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1533d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1534d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 1535d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff return T->getStmtClass() == TypesCompatibleExprClass; 1536d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1537d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 15381237c673c07f9d827129ba02720108816abde562Ted Kremenek 15391237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 15401237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 15411237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1542d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1543d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1544d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1545d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 1546d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 1547d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 1548d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 1549d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 1550d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 1551d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 1552d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 1553d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 1554d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 1555d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1556d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 1557d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 1558d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 1559d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 15605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 1561d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 1562d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1563d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 1564d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ShuffleVectorExpr(Expr **args, unsigned nexpr, 1565d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman QualType Type, SourceLocation BLoc, 1566d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation RP) : 1567d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc), 1568f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek RParenLoc(RP), NumExprs(nexpr) { 1569f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek 15705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[nexpr]; 1571d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 1572d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 1573d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1574d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1575d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 1576d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 1577d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1578d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 1579d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return T->getStmtClass() == ShuffleVectorExprClass; 1580d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1581d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 1582d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1583d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ~ShuffleVectorExpr() { 1584d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman delete [] SubExprs; 1585d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1586d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1587d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 1588d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 1589d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 1590d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 1591d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1592d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 1593d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 1594d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 15955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1596d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1597d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 1598d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 15995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1600d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1601d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1602dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 1603dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 1604a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue(); 1605d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1606d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1607d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 1608d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 1609d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 1610d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1611d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1612d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1613d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 1614d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1615d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 1616d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with 1617d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 16187976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 16197976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 16207976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 16217976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 16227976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 16237976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 1624d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 16251237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 16265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 1627d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1628d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 1629d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 1630d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation RP) 1631d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff : Expr(ChooseExprClass, t), 16321237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 16331237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 16341237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 16351237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 16361237c673c07f9d827129ba02720108816abde562Ted Kremenek } 16377976932a1c256d447316ffac58e9821417725e34Eli Friedman 16387976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 16397976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 164027437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 16417976932a1c256d447316ffac58e9821417725e34Eli Friedman 16427976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 16437976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 16447976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 16457976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 16467976932a1c256d447316ffac58e9821417725e34Eli Friedman } 16477976932a1c256d447316ffac58e9821417725e34Eli Friedman 16485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 16495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 16505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 16511237c673c07f9d827129ba02720108816abde562Ted Kremenek 1652d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 1653d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1654d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1655d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 1656d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return T->getStmtClass() == ChooseExprClass; 1657d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1658d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 16591237c673c07f9d827129ba02720108816abde562Ted Kremenek 16601237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 16611237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 16621237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1663d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1664d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1665d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1666d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 1667d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 16682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 16692d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 16702d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 16712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 16722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 16732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 16742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 16752d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 16762d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 16772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16782d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 16792d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor GNUNullExpr(QualType Ty, SourceLocation Loc) 16802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { } 16812d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 16832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 16842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16852d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 16862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 16872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 16882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 16892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return T->getStmtClass() == GNUNullExprClass; 16902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 16912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 16922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 16942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 16952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 16962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 16982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 16992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 17002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 17017c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start. 17027c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 17035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 17047c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 17057c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 17067c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 17077c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson : Expr(VAArgExprClass, t), 17087c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 17097c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 17107c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 17117c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 17125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 17135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 17147c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 17157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 17167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 17177c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 17187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 17197c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 17207c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 17217c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 17227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 17237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 17247c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_end(); 1725d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1726d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1727d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 17287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 17297c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 17304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 17314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 17324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 17334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 17344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 17354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 17364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 17374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 17384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 1739196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 17404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 17414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 17424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 17434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 17444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 17454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 17464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 17474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 1748196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 17494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 17504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 17514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 17524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 17534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 17544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 17554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 17563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 17574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 17584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 17594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 1760196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 17614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 17624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 17634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 17644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 17654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 17664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 176766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 17685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek std::vector<Stmt *> InitExprs; 176966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 1770418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner 17714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 17724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 17734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 17744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 17750bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 17760bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 17770bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 17780bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1779a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 1780a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 1781a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 1782a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 178366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 178466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 17854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc); 178666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 1787c5ae899b4bbf65488445316c63168079177db0edSteve Naroff unsigned getNumInits() const { return InitExprs.size(); } 178866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 178966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson const Expr* getInit(unsigned Init) const { 1790c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 17914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 179266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 179366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 179466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson Expr* getInit(unsigned Init) { 1795c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 17964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 179766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 179866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 17999e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff void setInit(unsigned Init, Expr *expr) { 1800c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 18019e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 18029e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 1803c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 1804fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 1805fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor void reserveInits(unsigned NumInits); 1806fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 18074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 18084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 18094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 18104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 18114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 18124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 18134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 18144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 18154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 18164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 18174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 18184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 18194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 18204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 18214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 18224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *updateInit(unsigned Init, Expr *expr); 1823c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 18240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 18250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 18260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 18270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 18280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 18290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 18300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 18310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 18320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1833c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 1834c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 1835b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 1836b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 1837b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 18389e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff 183987fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 184087fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 18414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 18424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 18434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 18444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 18454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 18464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 18474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1848a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 1849a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor void sawArrayRangeDesignator() { 1850a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor HadArrayRangeDesignator = true; 1851a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 1852a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 185366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 185466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 185566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 185666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 185766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return T->getStmtClass() == InitListExprClass; 185866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 185966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 186066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 186166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 186266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 186366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 18646336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek 18657fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::iterator iterator; 18667fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::reverse_iterator reverse_iterator; 18677fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek 18687fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator begin() { return InitExprs.begin(); } 18697fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator end() { return InitExprs.end(); } 18707fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 18717fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rend() { return InitExprs.rend(); } 18727fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek 18737fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek // Serailization. 18746336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1875e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 18766336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek 18776336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenekprivate: 18786336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek // Used by serializer. 187928a309e387a0a69b0c055c1565aa147fc695f906Chris Lattner InitListExpr() : Expr(InitListExprClass, QualType()) {} 188066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 188166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 188205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 188305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 188405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 188505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 188605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 188705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 188805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 188905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 189005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 189105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 189205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 189305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 189405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 189505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 189605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 189705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 189805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 189905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 190005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 190105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 190205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 190305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 190405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 190505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 190605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1907eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 190805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 1909eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 191005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 191105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 191205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 191305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 191405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 191505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 191605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 191705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 191805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 191905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 1920eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 192105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs) 192205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Expr(DesignatedInitExprClass, Ty), 1923eeae8f072748affce25ab4064982626361293390Douglas Gregor EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 192405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor NumDesignators(NumDesignators), NumSubExprs(NumSubExprs) { } 192505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 192605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 192705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 192805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 192905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 193005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 193105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 193205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 193305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 193405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 193505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 193605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 193705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 193805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 193905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 194005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 194105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 194205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 194305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 194405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 194505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 194605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 194705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 194805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 194905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 195005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 195105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 195205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 195305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 195405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 195505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned RBracketLoc; 195605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 195705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 195805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 195905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 196005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 196105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 196205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 196305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 196405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 196505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 196605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 196705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 196805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 196905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 197005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 197105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 197205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 197305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 197405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 197505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 197605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 197705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 197805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 197905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 198005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 198105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 198205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 198305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation FieldLoc) 198405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 198505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 198605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 198705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 198805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 198905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 199005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 199105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 199205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 199305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 199405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 199505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 199605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 199705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 199805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 199905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 200005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 200105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 200205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 200305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 200405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 200505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 200605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 200705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 200805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 200905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 202205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 202305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 202405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 202505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 202705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 202987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 203087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 203187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 203287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 203387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 203405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 203905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 204005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 204105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 204205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 204605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 204705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 204805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 204905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 205005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 205105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 205205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 205305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 205405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 205505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 20564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 20574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 20584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 20594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 20604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 20614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 20624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 206305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 206405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 206505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 206605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 206705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 206805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 2069eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 207005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 207105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 207205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 207305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 207405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 207505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 207605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor designators_iterator designators_begin(); 207705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor designators_iterator designators_end(); 207805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 207905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 208005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 208105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 208205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 208305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 208405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 208505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 208605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 208705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 2088eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 2089eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 209005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 209105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 209205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getInit() const { 209305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 209405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 209505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 209605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 209705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 209805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 209905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 210005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 210105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 210205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 210305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return T->getStmtClass() == DesignatedInitExprClass; 210405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 210505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 210605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 210705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 210805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 21093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_end(); 21103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 21113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 21133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 21143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 21151a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 21161a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 21173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 21181a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 21191a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 21203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr { 21213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 21223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor explicit ImplicitValueInitExpr(QualType ty) 21233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor : Expr(ImplicitValueInitExprClass, ty) { } 21243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const Stmt *T) { 21263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 21273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 21283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 21293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21303498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 21313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 21323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 21333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 21353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 213605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_end(); 213705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 213805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 21394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 21404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 21414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 21424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2143a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2144a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 2145a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 2146a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 2147a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 214873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 214973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 215073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 2151a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 2152a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 2153a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner IdentifierInfo &Accessor; 2154a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 2155a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 2156a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 2157a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 2158a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(ExtVectorElementExprClass, ty), 2159a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Base(base), Accessor(accessor), AccessorLoc(loc) {} 2160a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2161a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 2162a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 2163a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2164a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner IdentifierInfo &getAccessor() const { return Accessor; } 2165a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2166a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 2167a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 2168a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2169a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 2170a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 2171a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 2172a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2173a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 2174a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 2175a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 2176a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2177a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 2178a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 2179a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2180a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 21812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 21822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 21832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 21842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2185a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const Stmt *T) { 2186a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return T->getStmtClass() == ExtVectorElementExprClass; 2187a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2188a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 2189a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2190a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 2191a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 2192a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 2193d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 2194d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 2195d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 2196a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 2197a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2198a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 219956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 22009c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 22014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 220256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 220356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 2204b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 22054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 2206b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 2207b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump : Expr(BlockExprClass, ty), 2208b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 22099c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 2210d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 221156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 221256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 221356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 221456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 221556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 221656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 22179c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 22189c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 221956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 22209c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 22219c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 222256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 222356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 222456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 2225b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 2226b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// contained inside. 2227b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 2228b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 22294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 22309c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 22314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 22324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 22334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 22354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 22364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 223756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 22384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 22399c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 22404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 22419c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 22424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 22434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 22444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 22454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *D; 22464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 22474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool IsByRef; 22484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 22494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) : 22504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {} 22514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22524eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 22534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 22544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 22554eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 22574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 22594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff return T->getStmtClass() == BlockDeclRefExprClass; 22604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 22614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 22624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 22644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 22654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 22664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 22684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 22694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 22704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 22725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2274