Expr.h revision bc736fceca6f0bca31d16003a7587857190408fb
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 66f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregorpublic: 67f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 68f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor void setType(QualType t) { 699d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 709d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 719d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 76f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor assert((TR.isNull() || !TR->isReferenceType()) && 778320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 78f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 79f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor TR = t; 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 82898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 83898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 84898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 85898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent. 86898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 87898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isValueDependent() const { return ValueDependent; } 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<typename T> 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isTypeDependent() const { return TypeDependent; } 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 113026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 114026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 115026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 116026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 117026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 118026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceRange &R2) const; 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// incomplete type other than void. Nonarray expressions that can be lvalues: 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - name, where name must be a variable 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e[i] 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - (e), where e must be an lvalue 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e.name, where e must be an lvalue 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - e->name 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - *e, the type of e cannot be a function type 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// - string-constant 12908ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling /// - reference type [C++ [expr]] 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isLvalueResult { 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 135fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 13686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 13786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_MemberFunction 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 13928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult isLvalue(ASTContext &Ctx) const; 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and if it is a structure or union, does not have any member (including, 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 150fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 152ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1554f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1565daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 157ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 15886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 15986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_MemberFunction 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 16128be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const; 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16327c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor bool isBitField(); 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 165cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// getIntegerConstantExprValue() - Return the value of an integer 166cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// constant expression. The expression must be a valid integer 167cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar /// constant expression as determined by isIntegerConstantExpr. 168cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const { 1698070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 170cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar bool success = isIntegerConstantExpr(X, Ctx); 171a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar success = success; 172cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar assert(success && "Illegal argument to getIntegerConstantExpr"); 173cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar return X; 174cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar } 175cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 180590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 181590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 1832d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx, 1842d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar SourceLocation *Loc = 0, 1852d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar bool isEvaluated = true) const; 186590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 1878070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 188590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 190c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 191c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 192c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman bool isConstantInitializer(ASTContext &Ctx) const; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 19594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 1962d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 19794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 19894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 19994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 20094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 20194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 20294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 20394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 20594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 20694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 2186ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 219019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 220019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 221019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 2225b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 2235b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 2246ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 22545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 22645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 227c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 22851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 22951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 23051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 23151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 232efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 233efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 234efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 235efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson bool isNullPointerConstant(ASTContext &Ctx) const; 236efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 2372e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek /// hasGlobalStorage - Return true if this expression has static storage 2384cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// duration. This means that the address of this expression is a link-time 2394cc627111453b75519d5130b57e06256da7b00e8Chris Lattner /// constant. 2402e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek bool hasGlobalStorage() const; 24144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian 24244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 24344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// write barrier. 24444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian bool isOBJCGCCandidate() const; 2454e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 2464e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 2474e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// its subexpression. If that subexpression is also a ParenExpr, 2484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 2494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 2504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* IgnoreParens(); 25156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 25256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 25327c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 25456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 2554e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 256ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 257ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 258ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 259ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 260ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 2614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek const Expr* IgnoreParens() const { 2624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 2634e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 26456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 26556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 26656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 267ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 268ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 269ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 270ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 271898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 272898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 273898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getStmtClass() <= lastExprConstant; 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 2792e7d352dbec06755105237afba183492d31d03cbTed Kremenek 280e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) { 281e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop return cast<Expr>(Stmt::Create(D, C)); 2822e7d352dbec06755105237afba183492d31d03cbTed Kremenek } 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 2865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 2938e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *D; 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 2959e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 2969e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected: 2971a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // FIXME: Eventually, this constructor will go away and all subclasses 2981a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor // will have to provide the type- and value-dependent flags. 2998e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) : 3009e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis Expr(SC, t), D(d), Loc(l) {} 3019e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 3021a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD, 3031a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor bool VD) : 3041a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor Expr(SC, t, TD, VD), D(d), Loc(l) {} 3051a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: Eventually, this constructor will go away and all clients 308898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // will have to provide the type- and value-dependent flags. 3098e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) : 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr(DeclRefExprClass, t), D(d), Loc(l) {} 311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 312898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) : 313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {} 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3158e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor NamedDecl *getDecl() { return D; } 3168e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor const NamedDecl *getDecl() const { return D; } 317904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor void setDecl(NamedDecl *NewD) { D = NewD; } 318904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 3199e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 3239e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis return T->getStmtClass() == DeclRefExprClass || 3241a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == CXXConditionDeclExprClass || 3251a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor T->getStmtClass() == QualifiedDeclRefExprClass; 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 32877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 32977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 33077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 33177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3322dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 333ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 334e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 337d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 338d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 339227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 340227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 341227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 342227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 343cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor PrettyFunction 344227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 345227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 346227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 347227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 348227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 349227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 350d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 351d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {} 352227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 353227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 354227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 355227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 356227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 357227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson static bool classof(const Stmt *T) { 358d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner return T->getStmtClass() == PredefinedExprClass; 359227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 360d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 36177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 36277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 36377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 36477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3651ba485e582edfc8636afc25a6d7453c869530688Ted Kremenek 366ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 367d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 368227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 369227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::APInt Value; 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::APInt &getValue() const { return Value; } 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 383313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 384313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 385313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == IntegerLiteralClass; 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 39077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 39177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 39277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 39377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 3942dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 395ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 396e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 402c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 405c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 406c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) { 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4082eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner SourceLocation getLoc() const { return Loc; } 409c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 4102eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == CharacterLiteralClass; 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 41977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 42077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 42177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 42277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 4237338a8299ec393eaf6bb580b5ef9ab2b08b5bd11Ted Kremenek 424ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 425e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 429525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner llvm::APFloat Value; 430720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 433720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek FloatingLiteral(const llvm::APFloat &V, bool* isexact, 434720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 435720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {} 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 437c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner const llvm::APFloat &getValue() const { return Value; } 438720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek 439720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 440c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 441da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 442da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 443da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 444da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 445da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == FloatingLiteralClass; 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 45277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 45377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 45477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 45577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 456612c9b9ca73593b3194866c9e1a51554db9752e7Ted Kremenek 457ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 458e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4615d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 4625d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 4635d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 4645d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 4655d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 4665d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 4675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 4685d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 4695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 4705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 4715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 4725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 4735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 4745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 4755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 4765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const Stmt *T) { 4775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner return T->getStmtClass() == ImaginaryLiteralClass; 4785d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 4795d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 4805d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 4815d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 4825d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 4835d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 4841c72de1be77fc43cc27e9bf1cbfe7bd25bee2f81Ted Kremenek 485ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 486e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 4875d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 4885d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 489e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 490e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 491e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 492a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 493c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 494c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 495690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 496690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 4978bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 498690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 499c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 500c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 501c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 502c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 503c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 504c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 509726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 510726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 5112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {} 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 5152085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 5162085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 5182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SourceLocation *Loc, unsigned NumStrs); 5192085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 5202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 5212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 5222085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 5232085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 5242085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 5252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 5266e94ef5696cfb005d3fc7bbac8dcf7690b64f0a5Ted Kremenek 527726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner void Destroy(ASTContext &C); 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getStrData() const { return StrData; } 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 532726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 533726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 534726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 535726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 536726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 537726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 538726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 539726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 540726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 541b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner 542b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 543b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 544b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 547726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == StringLiteralClass; 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 55377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 55477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 55577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 55677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5577febad7377c04607aa2c744d58af61e1abea6250Ted Kremenek 558ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 559e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C); 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 5665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 569898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor val->isTypeDependent(), val->isValueDependent()), 571898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 5745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 575866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 577313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 578313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 579313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 580313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 581313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 582313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ParenExprClass; 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 58777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 58877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 58977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 59077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 5919eea2ca5f2cb5d77569274702b5b06273e426dc2Ted Kremenek 592ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 593e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 5980518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 600dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 601dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 602dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 603dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 604dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 605dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 606dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 60773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 60873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// subexpression is a compound literal with the various MemberExpr and 60973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// ArraySubscriptExpr's applied to it. 61073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 61313d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner // Note that additions to this should also update the StmtVisitor class. 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Real, Imag, // "__real expr"/"__imag expr" Extension. 62173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner Extension, // __extension__ marker. 62273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner OffsetOf // __builtin_offsetof 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 6255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode Opc; 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 6319103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor : Expr(UnaryOperatorClass, type, 6329103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isTypeDependent() && opc != OffsetOf, 6339103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor input->isValueDependent()), 6349103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor Val(input), Opc(opc), Loc(l) {} 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 6375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 6432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 6442085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PostInc || Op == PostDec; 6452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6475a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek /// isPostfix - Return true if this is a prefix operation, like --x. 6482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 6492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Op == PreInc || Op == PreDec; 6502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 6515a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 6525a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek bool isPrefix() const { return isPrefix(Opc); } 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPostfix() const { return isPostfix(Opc); } 6545d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 6565a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson bool isOffsetOfOp() const { return Opc == OffsetOf; } 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 663bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 664bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 665bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 666bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 667bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 668bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 669bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 670bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == UnaryOperatorClass; 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 68377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 68477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 68577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 68677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 6871049436d4b53d928b555f7381bc1639dd302bbc7Ted Kremenek 688ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 689e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 6930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 6940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 6950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 6960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 697d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 698d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl void *Ty; 699d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 700d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 703ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, QualType T, 7040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 7050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 7062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl Expr(SizeOfAlignOfExprClass, resultType, 707ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 7082850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 709ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor T->isDependentType()), 710ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 711ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ty = T.getAsOpaquePtr(); 712ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 713ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 714ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SizeOfAlignOfExpr(bool issizeof, Expr *E, 715ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 716ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 717ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Expr(SizeOfAlignOfExprClass, resultType, 718ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 719ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 720ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 721ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 722ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 723d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 7240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 7259048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar virtual void Destroy(ASTContext& C); 7269048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 7280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 7290518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 7300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 731d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return QualType::getFromOpaquePtr(Argument.Ty); 7320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 733caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 7340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 735d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 7360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 737caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 738caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 739caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 740caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner 7410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 7420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 7430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 7440518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 7450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 7460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 74776e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 748866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 749866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 750866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 751866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 7540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return T->getStmtClass() == SizeOfAlignOfExprClass; 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 75777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 75877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 75977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 76077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 761ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek 762ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 7630518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 77277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 7735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7762324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 77773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 7782850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl : Expr(ArraySubscriptExprClass, t, 7792850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 7802850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 7812850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 78273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 78373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 78473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7862324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 7872324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 7882324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 7892324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 7902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 79133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 79233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 79333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 79433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 7955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 7965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 79777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 7985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 7995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 8002324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 80177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getBase() { 8025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 80377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 80477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 8052324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek const Expr *getBase() const { 8065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 8072324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 8082324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 80977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek Expr *getIdx() { 8105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 8112324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 8122324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek 81377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 8145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 81577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 817866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 81877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 820866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 821026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 8225cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ArraySubscriptExprClass; 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 82877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 82977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 83077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 83177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 83296fa54fc6dc7f4c8dad1fb22fc7fc4f4d775d6c0Ted Kremenek 833ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 834e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 838b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 839b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 840b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 841b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is 842b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 843b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 84577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 8465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 849d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 850d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek // This version of the ctor is for deserialization. 851b4609806e9232593ece09ce08b630836e825865cDouglas Gregor CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t, 852d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek SourceLocation rparenloc) 853b4609806e9232593ece09ce08b630836e825865cDouglas Gregor : Expr(SC,t), SubExprs(subexprs), 854d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek NumArgs(numargs), RParenLoc(rparenloc) {} 855b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 856b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 857b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 858668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 859668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc); 860d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 862668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation rparenloc); 864668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 865668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek ~CallExpr() {} 866668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 867668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek void Destroy(ASTContext& C); 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 8705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 87118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 8805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 8845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 886668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 887668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // FIXME: Why is this needed? Why not just create the CallExpr with the 888668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // corect number of arguments? It makes the ASTs less brittle. 889934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 890934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 891934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 892934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 893934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 894d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 895668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // FIXME: It would be great to just get rid of this. There is only one 896668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // callee of this method, and it probably could be refactored to not use 897668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // this method and instead just create a CallExpr with the right number of 898668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek // arguments. 899d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 900d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 901d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 9028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 903d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 9045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 9055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 9065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 907d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 908d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 9095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 9105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 911d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 916cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 917cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 9183c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 919cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 920d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 921866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 922866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 92377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 927b4609806e9232593ece09ce08b630836e825865cDouglas Gregor return T->getStmtClass() == CallExprClass || 92888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXOperatorCallExprClass || 92988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor T->getStmtClass() == CXXMemberCallExprClass; 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 93288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 93388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 93488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 93577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 93677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 93777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 938d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek 939ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 940b4609806e9232593ece09ce08b630836e825865cDouglas Gregor static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C, 941b4609806e9232593ece09ce08b630836e825865cDouglas Gregor StmtClass SC); 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 944ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 947ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 948ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 9495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 950ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 951ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 952ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 95386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *MemberDecl; 954ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 955ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 957ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 958ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 959ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner bool IsArrow; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 96186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l, 962510190777c4bd53e960eea4665b204778fec1b64Eli Friedman QualType ty) 963510190777c4bd53e960eea4665b204778fec1b64Eli Friedman : Expr(MemberExprClass, ty), 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {} 965510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 96688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 9675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 96886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *getMemberDecl() const { return MemberDecl; } 96988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setMemberDecl(NamedDecl *D) { MemberDecl = D; } 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 971ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner 972ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 973ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 974026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getBase()->getLocStart(), MemberLoc); 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 979866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == MemberExprClass; 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 9861237c673c07f9d827129ba02720108816abde562Ted Kremenek 9871237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 9881237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 9891237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 990bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek 991bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 992e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 995aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5] 996aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 997aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 9980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 9990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 10000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 10010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 10025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1003e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1004aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 1005a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, 1006a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool fileScope) 1007a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), 1008a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner FileScope(fileScope) {} 1009aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 10105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 10115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1012e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1013e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1014aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 10150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 10160fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner 101773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 10180fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 10190fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 10200fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 10210fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 102273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 10230fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 102473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1025aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 1026aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const Stmt *T) { 1027aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff return T->getStmtClass() == CompoundLiteralExprClass; 1028aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1029aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 10301237c673c07f9d827129ba02720108816abde562Ted Kremenek 10311237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 10321237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 10331237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 10344b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek 10354b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1036e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1037aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 1038aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 103949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 104049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 104149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 104249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 10430835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 10440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 10450835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 10460835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis CastExpr(StmtClass SC, QualType ty, Expr *op) : 1047898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr(SC, ty, 1048898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 1049898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 1050898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 1051898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 1052898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 1053898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType() || (op && op->isValueDependent())), 1054898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Op(op) {} 10550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 10560835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 10570835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 10580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 10590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 10600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const Stmt *T) { 10619d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 10629d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 10639d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 10649d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 10656eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass) 10660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return true; 10679d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 10689d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 10690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 10700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 10710835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 10720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 10730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 10740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 10750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 10760835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 107749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 107849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 107949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 108049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 108149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 1082bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 1083bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 1084bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example: 1085bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 1086bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 1087bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 1088bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 1089bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) { 1090bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base 1091bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 1092bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 10930835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 1094eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// LvalueCast - Whether this cast produces an lvalue. 1095eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool LvalueCast; 1096eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 109749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic: 1098eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) : 1099b3eef68111ffc220e449be96da1747998c057790Douglas Gregor CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { } 110090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 11010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 11020835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 11030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 110490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 1105eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// isLvalueCast - Whether this cast produces an lvalue. 1106eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor bool isLvalueCast() const { return LvalueCast; } 1107eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1108eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor /// setLvalueCast - Set whether this cast produces an lvalue. 1109eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; } 1110eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 111149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const Stmt *T) { 111249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff return T->getStmtClass() == ImplicitCastExprClass; 111349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 111449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 11151237c673c07f9d827129ba02720108816abde562Ted Kremenek 1116ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1117e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 111849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 111949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 112049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 112149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code. 112249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 112349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 112449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 112549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 112649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 112749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 112949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 113049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 113149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 113249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 113349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 113449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will 113549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression. 11360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 113749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// TypeAsWritten - The type that this expression is casting to, as 113849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// written in the source code. 113949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType TypeAsWritten; 114049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 114149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 11428320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy) 11438320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {} 114449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 114549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 114649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 114749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 114849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor QualType getTypeAsWritten() const { return TypeAsWritten; } 114949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 115049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const Stmt *T) { 11519d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor StmtClass SC = T->getStmtClass(); 11526eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass) 11539d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return true; 11549d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass) 115549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 11569d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor 11579d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return false; 115849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 115949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 116049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 116149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 11626eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 116349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 116449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 11656eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 1166b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 1167b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11696eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy, 1170b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation l, SourceLocation r) : 1171b2f9e516327310d95840d442416084508f80c183Steve Naroff ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), 1172b2f9e516327310d95840d442416084508f80c183Steve Naroff LPLoc(l), RPLoc(r) {} 117349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 1174b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 1175b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 1178b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 11816eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor return T->getStmtClass() == CStyleCastExprClass; 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11836eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 11849971c9ace70624987cd74645a75f4bfbc05afdf2Ted Kremenek 1185ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 11866eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 11903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 11913fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 11923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 11933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 11943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 11953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 11963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 11973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 11983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 11993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 12003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 12013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 12023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 12033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 12043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 12053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 12063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Opcode { 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Operators listed in order of precedence. 121103d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner // Note that additions to this should also update the StmtVisitor class. 1212224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Add, Sub, // [C99 6.5.6] Additive operators. 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer EQ, NE, // [C99 6.5.9] Equality operators. 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer And, // [C99 6.5.10] Bitwise AND operator. 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Xor, // [C99 6.5.11] Bitwise XOR operator. 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Or, // [C99 6.5.12] Bitwise OR operator. 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LAnd, // [C99 6.5.13] Logical AND operator. 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LOr, // [C99 6.5.14] Logical OR operator. 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Assign, MulAssign,// [C99 6.5.16] Assignment operators. 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DivAssign, RemAssign, 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AddAssign, SubAssign, 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ShlAssign, ShrAssign, 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer AndAssign, XorAssign, 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer OrAssign, 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Comma // [C99 6.5.17] Comma operator. 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 123117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 123217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 12335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 123417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner Opcode Opc; 123517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc; 123617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic: 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 123817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 123917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 1240898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(BinaryOperatorClass, ResTy, 1241898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 1242898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent()), 1243898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 12441237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 12451237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isCompoundAssignmentOp() && 12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 125017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Opcode getOpcode() const { return Opc; } 12525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 12535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1262063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 1263063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 1264063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 1265063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1266063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1267063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 1268063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1269063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftOp() const { return Opc == Shl || Opc == Shr; } 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 1275f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1276f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 1277f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isRelationalOp() const { return isRelationalOp(Opc); } 1278f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1279f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 1280f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isEqualityOp() const { return isEqualityOp(Opc); } 1281f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 1282f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 1283f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek bool isLogicalOp() const { return isLogicalOp(Opc); } 1284f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1289eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner static bool classof(const Stmt *S) { 1290eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == BinaryOperatorClass || 1291eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner S->getStmtClass() == CompoundAssignOperatorClass; 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 12941237c673c07f9d827129ba02720108816abde562Ted Kremenek 12951237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 12961237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 12971237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 12982dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek 1299ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1300e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 13011237c673c07f9d827129ba02720108816abde562Ted Kremenek 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 130317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 130417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation oploc, bool dead) 130517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 13061237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 13071237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ComputationType; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 132117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner QualType ResType, QualType CompType, 132217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 132317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 132417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner ComputationType(CompType) { 13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(isCompoundAssignmentOp() && 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getComputationType() const { return ComputationType; } 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *S) { 1333eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner return S->getStmtClass() == CompoundAssignOperatorClass; 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 133583efb151a0c1df8cb8fb25d6dbb6c0f12f07f60aTed Kremenek 1336ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1337e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D, 1338e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop ASTContext& C); 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 13451237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 13465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t) 1349898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ConditionalOperatorClass, t, 1350898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 1351898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 1352898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 1353898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 1354898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (cond->isValueDependent() || 1355898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 1356898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (rhs && rhs->isValueDependent()))) { 13571237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 13581237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 13591237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 13601237c673c07f9d827129ba02720108816abde562Ted Kremenek } 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1362395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 1363395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 13645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 1365395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1366395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1367395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to true. In most cases this value 1368395a2abf0028968d85958610e393e067885dc14fTed Kremenek // will be the same as getLHS() except a GCC extension allows the left 1369395a2abf0028968d85958610e393e067885dc14fTed Kremenek // subexpression to be omitted, and instead of the condition be returned. 1370395a2abf0028968d85958610e393e067885dc14fTed Kremenek // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 1371395a2abf0028968d85958610e393e067885dc14fTed Kremenek // is only evaluated once. 1372395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 13735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 1374395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 1375395a2abf0028968d85958610e393e067885dc14fTed Kremenek 1376395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 1377395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 13785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 1379395a2abf0028968d85958610e393e067885dc14fTed Kremenek 13805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 13815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() == ConditionalOperatorClass; 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 13901237c673c07f9d827129ba02720108816abde562Ted Kremenek 13911237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 13921237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 13931237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1394aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1395ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1396e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C); 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13996481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 14006481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14046481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 14056481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 14066481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 14156481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner return T->getStmtClass() == AddrLabelExprClass; 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14176481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 14181237c673c07f9d827129ba02720108816abde562Ted Kremenek 14191237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14201237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14211237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1422aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1423ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1424e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1426ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1427ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 1428ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 1429ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 1430ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 14315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 1432ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 1433ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 1434d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 1435d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 1436d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 1437ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 14385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 14395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 1440ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1441ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 1442ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 1443ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1445026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1446026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 1447026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 1448ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 1449ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return T->getStmtClass() == StmtExprClass; 1450ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 1451ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 14521237c673c07f9d827129ba02720108816abde562Ted Kremenek 14531237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14541237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14551237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1456aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek 1457ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1458e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1459ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 1460ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 1461d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p. 1462d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 1463d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 1464d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 1465d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 1466d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type1; 1467d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType Type2; 1468363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1469d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 1470363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 1471d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff QualType t1, QualType t2, SourceLocation RP) : 1472d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 1473363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff BuiltinLoc(BLoc), RParenLoc(RP) {} 1474d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 14757f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType1() const { return Type1; } 14767f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff QualType getArgType2() const { return Type2; } 1477ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff 1478d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 1479363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1480d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1481d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 1482d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff return T->getStmtClass() == TypesCompatibleExprClass; 1483d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 1484d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 14851237c673c07f9d827129ba02720108816abde562Ted Kremenek 14861237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 14871237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 14881237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1489d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1490d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1491d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1492d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 1493d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 1494d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 1495d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 1496d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 1497d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 1498d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 1499d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 1500d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 1501d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 1502d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1503d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 1504d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 1505d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 1506d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 15075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 1508d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 1509d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1510d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 1511d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ShuffleVectorExpr(Expr **args, unsigned nexpr, 1512d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman QualType Type, SourceLocation BLoc, 1513d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation RP) : 1514d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc), 1515f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek RParenLoc(RP), NumExprs(nexpr) { 1516f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek 15175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[nexpr]; 1518d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 1519d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 1520d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1521d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1522d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 1523d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 1524d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1525d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 1526d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return T->getStmtClass() == ShuffleVectorExprClass; 1527d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1528d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 1529d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1530d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman ~ShuffleVectorExpr() { 1531d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman delete [] SubExprs; 1532d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1533d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1534d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 1535d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 1536d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 1537d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 1538d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1539d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 1540d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 1541d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 15425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1543d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1544d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 1545d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 15465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 1547d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1548d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1549dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 1550dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 1551a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue(); 1552d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 1553d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1554d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 1555d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 1556d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 1557d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1558d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1559d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1560d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 1561d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 1562d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 1563d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with 1564d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 15657976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 15667976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 15677976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 15687976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 15697976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 15707976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 1571d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 15721237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 15735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 1574d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 1575d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 1576d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 1577d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation RP) 1578d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff : Expr(ChooseExprClass, t), 15791237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 15801237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 15811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 15821237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 15831237c673c07f9d827129ba02720108816abde562Ted Kremenek } 15847976932a1c256d447316ffac58e9821417725e34Eli Friedman 15857976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 15867976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 158727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 15887976932a1c256d447316ffac58e9821417725e34Eli Friedman 15897976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 15907976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 15917976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 15927976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 15937976932a1c256d447316ffac58e9821417725e34Eli Friedman } 15947976932a1c256d447316ffac58e9821417725e34Eli Friedman 15955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 15965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 15975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 15981237c673c07f9d827129ba02720108816abde562Ted Kremenek 1599d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 1600d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 1601d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1602d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 1603d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return T->getStmtClass() == ChooseExprClass; 1604d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 1605d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 16061237c673c07f9d827129ba02720108816abde562Ted Kremenek 16071237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 16081237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 16091237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 1610d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1611d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1612d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 1613d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 1614d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 16152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 16162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 16172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 16182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 16192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 16202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 16212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 16222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 16232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 16242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 16262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor GNUNullExpr(QualType Ty, SourceLocation Loc) 16272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { } 16282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 16302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 16312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 16332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 16342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 16352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 16362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return T->getStmtClass() == GNUNullExprClass; 16372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 16382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 16392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 16412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 16422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 16432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 16452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 16462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 16472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 16487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start. 16497c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 16505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 16517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 16527c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 16537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 16547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson : Expr(VAArgExprClass, t), 16557c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson Val(e), 16567c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 16577c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 16587c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 16595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 16605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 16617c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 16627c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 16637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 16647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 16657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 16667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 16677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 16687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 16697c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 16707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 16717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_end(); 1672d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 1673d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 1674d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 16757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 16767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 16774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 16784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 16794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 16804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 16814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 16824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 16834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 16844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 16854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 1686196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 16874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 16884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 16894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 16904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 16914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 16924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 16934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 16944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 1695196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 16964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 16974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 16984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 16994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 17004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 17014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 17024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 17033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 17044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 17054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 17064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 1707196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 17084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 17094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 17104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 17114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 17124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 17134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 171466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 17155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek std::vector<Stmt *> InitExprs; 171666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 1717418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner 17184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 17194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 17204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 17214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 17220bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 17230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 17240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 17250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1726a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 1727a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 1728a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 1729a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 173066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 173166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 17324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc); 173366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 1734c5ae899b4bbf65488445316c63168079177db0edSteve Naroff unsigned getNumInits() const { return InitExprs.size(); } 173566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 173666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson const Expr* getInit(unsigned Init) const { 1737c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 17384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 173966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 174066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 174166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson Expr* getInit(unsigned Init) { 1742c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 17434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 174466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 174566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 17469e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff void setInit(unsigned Init, Expr *expr) { 1747c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 17489e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 17499e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 1750c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 17514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 17524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 17534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 17544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 17554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 17564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 17574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 17584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 17594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 17604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 17614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 17624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 17634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 17644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 17654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 17664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *updateInit(unsigned Init, Expr *expr); 1767c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 17680bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 17690bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 17700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 17710bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 17720bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 17730bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 17740bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 17750bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 17760bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 1777c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 1778c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 1779b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 1780b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 1781b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 17829e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff 178387fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 178487fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 17854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 17864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 17874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 17884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 17894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 17904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 17914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1792a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 1793a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor void sawArrayRangeDesignator() { 1794a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor HadArrayRangeDesignator = true; 1795a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 1796a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 179766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual SourceRange getSourceRange() const { 179866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return SourceRange(LBraceLoc, RBraceLoc); 179966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 180066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 180166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson return T->getStmtClass() == InitListExprClass; 180266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 180366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 180466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 180566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 180666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 180766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 18086336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek 18097fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::iterator iterator; 18107fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek typedef std::vector<Stmt *>::reverse_iterator reverse_iterator; 18117fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek 18127fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator begin() { return InitExprs.begin(); } 18137fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek iterator end() { return InitExprs.end(); } 18147fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 18157fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek reverse_iterator rend() { return InitExprs.rend(); } 18167fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek 18177fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek // Serailization. 18186336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1819e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 18206336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek 18216336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenekprivate: 18226336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek // Used by serializer. 182328a309e387a0a69b0c055c1565aa147fc695f906Chris Lattner InitListExpr() : Expr(InitListExprClass, QualType()) {} 182466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 182566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 182605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 182705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 182805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 182905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 183005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 183105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 183205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 183305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 183405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 183505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 183605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 183705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 183805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 183905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 184005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 184105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 184205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 184305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 184405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 184505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 184605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 184705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 184805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 184905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 185005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 185105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Whether this designated initializer used the GNU deprecated ':' 185205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 185305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax : 1; 185405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 185505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 185605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 185705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 185805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 185905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 186005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 186105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 186205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 186305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 186405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, bool UsesColonSyntax, 186505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs) 186605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Expr(DesignatedInitExprClass, Ty), 186705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor EqualOrColonLoc(EqualOrColonLoc), UsesColonSyntax(UsesColonSyntax), 186805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor NumDesignators(NumDesignators), NumSubExprs(NumSubExprs) { } 186905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 187005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 187105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 187205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 187305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 187405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 187505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 187605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 187705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 187805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 187905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 188005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 188105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 188205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 188305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 188405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 188505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 188605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 188705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 188805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 188905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 189005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 189105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 189205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 189305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 189405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 189505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 189605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 189705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 189805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 189905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned RBracketLoc; 190005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 190105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 190205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 190305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 190405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 190505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 190605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 190705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 190805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 190905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 191005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 191105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 191205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 191305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 191405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 191505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 191605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 191705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 191805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 191905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 192005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 192105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 192205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 192305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 192405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 192505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 192605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 192705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation FieldLoc) 192805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 192905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 193005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 193105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 193205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 193305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 193405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 193505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 193605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 193705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 193805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 193905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 194005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 194105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 194205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 194305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 194405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 194505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Designator(unsigned Index, SourceLocation LBracketLoc, 194605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 194705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 194805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 194905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 195005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 195105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 195205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 195305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 195405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 195505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 195605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 195705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 195805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 195905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 196005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 196105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 196205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 196305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 196405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 196505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 196605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 196705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 196805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 196905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 197005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 197105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 197205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 197387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 197487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 197587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 197687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 197787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 197805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 197905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 198005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 198105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 198205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 198305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 198405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 198505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 198605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 198705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 198805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 198905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 199005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 199105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 199205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 199305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 199405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 199505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 199605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 199705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 199805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 199905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 20004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 20014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 20024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 20034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 20044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 20054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 20064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 200705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 200805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 200905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init); 201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor designators_iterator designators_begin(); 202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor designators_iterator designators_end(); 202205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 202305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 202405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 202505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 202705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 202905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 203005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 203105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 203205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// GNU 'fieldname:' syntax or the C99 '=' syntax. 203305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool usesColonSyntax() const { return UsesColonSyntax; } 203405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getInit() const { 203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 203905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 204005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 204105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 204205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 204605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 204705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return T->getStmtClass() == DesignatedInitExprClass; 204805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 204905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 205005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 205105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 205205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 20533498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_end(); 20543498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 20553498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 20573498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 20583498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 20591a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 20601a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 20613498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 20621a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 20631a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 20643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr { 20653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 20663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor explicit ImplicitValueInitExpr(QualType ty) 20673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor : Expr(ImplicitValueInitExprClass, ty) { } 20683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const Stmt *T) { 20703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 20713498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 20723498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 20733498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 20753498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 20763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 20773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 20793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 208005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_end(); 208105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 208205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 20834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 20844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 20854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 20864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 2087a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2088a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 2089a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 2090a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 2091a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 209273525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 209373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 209473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 2095a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 2096a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 2097a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner IdentifierInfo &Accessor; 2098a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 2099a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 2100a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 2101a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation loc) 2102a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner : Expr(ExtVectorElementExprClass, ty), 2103a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Base(base), Accessor(accessor), AccessorLoc(loc) {} 2104a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2105a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 2106a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 2107a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2108a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner IdentifierInfo &getAccessor() const { return Accessor; } 2109a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2110a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 2111a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 2112a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2113a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 2114a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 2115a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 2116a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2117a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 2118a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 2119a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 2120a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2121a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 2122a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 2123a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2124a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 21252140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 21262140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 21272140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 21282140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2129a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const Stmt *T) { 2130a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return T->getStmtClass() == ExtVectorElementExprClass; 2131a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 2132a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 2133a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2134a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 2135a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 2136a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 2137d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar 2138d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const; 2139d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 2140a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 2141a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 2142a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 214356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 21449c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 21454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 214656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 214756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 2148b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 21494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 2150b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 2151b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump : Expr(BlockExprClass, ty), 2152b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 21539c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 2154d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 215556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 215656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 215756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 215856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 215956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 216056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 21619c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 21629c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 216356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 21649c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 21659c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 216656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 216756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 216856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 2169b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 2170b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// contained inside. 2171b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 2172b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 21734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 21749c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 21754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 21764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 21774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 21784eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 21794eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 21804eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 218156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 21824eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 21839c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 21844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 21859c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 21864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 21874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 21884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 21894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *D; 21904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 21914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool IsByRef; 21924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 21934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) : 21944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {} 21954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 21964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 21974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 21984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 21994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 22014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const Stmt *T) { 22034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff return T->getStmtClass() == BlockDeclRefExprClass; 22044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 22054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 22064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 22084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 22094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 22104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 22124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 22134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 22144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2218