Expr.h revision 7eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607
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" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 25525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 263b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 27b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 28c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector> 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 31590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 32c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 368e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 39409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 42833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 43d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 46f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 55bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner virtual void ANCHOR(); // key function. 565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool TD, bool VD) : Stmt(SC) { 608e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 62f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 63f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 71f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 80905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 818320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 82f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 86898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 87898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setValueDependent(bool VD) { ExprBits.ValueDependent = VD; } 970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 1128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setTypeDependent(bool TD) { ExprBits.TypeDependent = TD; } 1130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SourceLocation tokens are not useful in isolation - they are low level 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// value objects created/interpreted by SourceManager. We assume AST 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// clients will have a pointer to the respective SourceManager. 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const = 0; 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return getLocStart(); } 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 124026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 125026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 128df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1307eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1317eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1327eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1337eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1347eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1357eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1377eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1387eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1397eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1407eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1417eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 1427eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 1437eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 1447eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 1457eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 1467eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 1477eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 1487eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 152fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 15386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 1542514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 155e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 156e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 1587eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 1597eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 16053202857c60214d80950a975e6e52aebf30bd16aEli Friedman 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 16644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 16744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 16844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 16944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 174fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 176ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 1794f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 1805daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 181ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 18286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 1832514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 184e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 185e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 18744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 18844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 1912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 1922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 1932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 1942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 1952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 1962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 1972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 1982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 1992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 2042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 245369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 261369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 273f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 274f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 2770943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 2780943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 2790943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 2800943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 281f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 282f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 283f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 284f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 286f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 289f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 290f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 291f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 292f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 293f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 295f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 296f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 297f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 298f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 299f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 301f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 30733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 30833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 30933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 31138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 31238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 31338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 315093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 316093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 317c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3182b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3192b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3202b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3212b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3222b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 323c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 328590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 329590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 331590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 3328070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 333590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 335c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 336c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 3374204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 34094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 3412d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 34294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 34594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 34694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 34994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 35094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 35194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 35294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 35394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 35494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 35594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 35694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 35794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 35894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 361e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 362e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 363e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 364e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 365e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 366e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 367e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 368e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 369e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 37094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 37194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 3726ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 373019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 374019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 375019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 3765b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 3775b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 378cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 379cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 380cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 381cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 382cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 3836ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 38445b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 38545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner bool isEvaluatable(ASTContext &Ctx) const; 386c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 3876ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 388138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 3896ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 3906ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 391393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian bool HasSideEffects(ASTContext &Ctx) const; 392c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 39351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 39451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 39551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 39651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 397b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 398b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 3991b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 4001b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 401e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 404ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 405ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 406ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 407ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 408ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 409c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 410ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 411ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 412ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 413c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 414ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 415ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 416ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 417ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 418c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 419efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 420efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// integer constant expression with the value zero, or if this is one that is 421efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson /// cast to void*. 422ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor bool isNullPointerConstant(ASTContext &Ctx, 423ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const; 424efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 42544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 427102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42911ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 43011ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 43111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 432369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 433369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 434369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 435369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 436369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 437369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 438369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 439369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 440369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 441369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 4424e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 4444e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 4454e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 4462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 44756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 44856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 44927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 45056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4522fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 4532fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 4542fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 4552fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 4564d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 4574d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 4584d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 4594d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 460ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 461ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 462ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 463ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4656eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 4666eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 4676eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 4696eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 4706eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 4716eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 4726eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 473c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 474558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 475558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 476558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 4772f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 4782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 4794e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 4804e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 48156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 48256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 48356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 484ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 485ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 486ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 488898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 489898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 490898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 503a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the 504a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort". 505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier { 506a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The nested name specifier. 507a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *NNS; 508c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 509a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source range covered by the nested name specifier. 510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange Range; 511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 512a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 514a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 517a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 524a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 526c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 528833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 529833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 530a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 533833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 534833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 536d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 537d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 538d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 5398dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 540d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc. 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor enum { 547c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has a C++ nested-name-specifier. 549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasQualifierFlag = 0x01, 550c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // Flag on DecoratedD that specifies when this declaration reference 551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // expression has an explicit C++ template argument list. 552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor HasExplicitTemplateArgumentListFlag = 0x02 553a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor }; 554c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 555c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // DecoratedD - The declaration that we are referencing, plus two bits to 556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // indicate whether (1) the declaration's name was explicitly qualified and 557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // (2) the declaration's name was followed by an explicit template 558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // argument list. 559dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 5602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // Loc - The location of the declaration name itself. 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 5639e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// DNLoc - Provides source/type location info for the 5652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in DecoratedD. 5662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 5672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 568a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the declaration name, if any. 569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *getNameQualifier() { 5702cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 571a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 572c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 573a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return reinterpret_cast<NameQualifier *> (this + 1); 574a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 575c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor const NameQualifier *getNameQualifier() const { 578a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 580096832c5ed5b9106fa177ebc148489760c3bc496John McCall 581a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 582dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 583d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 584f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 585663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 5862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 5872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 5882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 589f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 5902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 591663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 592663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 593663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 5960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 5970da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 5989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 600f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, SourceLocation l) : 601f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(DeclRefExprClass, t, VK, OK_Ordinary, false, false), 602f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall DecoratedD(d, 0), Loc(l) { 6030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 6040da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 606a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 607a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 609dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 610a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 611f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 6120da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 613663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 6142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 6152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NestedNameSpecifier *Qualifier, 6162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 6172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 6182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 619f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 6202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 6212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 622663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 623663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 624663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis bool HasQualifier, unsigned NumTemplateArgs); 625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 626dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *getDecl() { return DecoratedD.getPointer(); } 627dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 628dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 629904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 6302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 6312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 6322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 6332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 6349e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 6350b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 636a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor virtual SourceRange getSourceRange() const; 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 639a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 640a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 642a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief If the name was qualified, retrieves the source range of 643a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// the nested-name-specifier that precedes the name. Otherwise, 644a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// returns an empty source range. 645a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange getQualifierRange() const { 646a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 647a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceRange(); 648c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 649a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->Range; 650a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 651c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 652c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// \brief If the name was qualified, retrieves the nested-name-specifier 653a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 655a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 656a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 657c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 658a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getNameQualifier()->NNS; 659a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 660c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 661096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 662096832c5ed5b9106fa177ebc148489760c3bc496John McCall return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag); 663096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 664096832c5ed5b9106fa177ebc148489760c3bc496John McCall 665096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 666096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 667096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 668096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 669096832c5ed5b9106fa177ebc148489760c3bc496John McCall 670096832c5ed5b9106fa177ebc148489760c3bc496John McCall if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 671096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 672096832c5ed5b9106fa177ebc148489760c3bc496John McCall 673096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 674096832c5ed5b9106fa177ebc148489760c3bc496John McCall getNameQualifier() + 1); 675096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 676096832c5ed5b9106fa177ebc148489760c3bc496John McCall 677096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 678096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 679096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 680096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 681a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 682d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 683096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 684096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 685096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 686096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 687096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 688096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 689096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 690096832c5ed5b9106fa177ebc148489760c3bc496John McCall 691d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 692d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 693d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 694096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 695096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 696d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 697c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 699a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 701096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 702a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 703c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 704096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 705a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 706c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 707a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 708a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 709833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 710096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 711a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 712c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 713096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 714a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 715c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 716a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 717a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 718a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 719096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 720a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 721c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 722096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 723a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 724c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 725a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 726a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 727a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 728096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 729a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 730c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 731096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 732a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 733c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 73599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 74077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 74177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 742663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 74360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 7443397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 747d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 748d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 749227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 750227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 751227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 752227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 753848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 754848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 755848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 756848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 757227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 759227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 760227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 761227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 762227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 764f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 765f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall type->isDependentType(), type->isDependentType()), 766f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 77017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 77117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 772227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 77317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 77417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 77517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 77617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 77717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 778848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 7793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 780227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 781227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 784227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 785d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 78877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 78977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 790227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 791227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 7929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 7939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 7949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 7959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 7969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 7979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 7989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 7999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 8009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 8019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 8029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 8039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 8049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 8059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 8069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 8089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 8109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 8119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 8139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 8149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 8169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 8179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 8189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 8199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 8209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 8219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 8229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 8239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 8249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 8269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 8279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 8289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 8299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 8309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 8329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 8339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 8349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 8359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 8369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 8379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 8389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 8409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 8449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 8459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 8469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 8509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 8519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 852f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false), 853f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 8559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 857a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 8589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 8599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis // or UnsignedLongLongTy 8609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 8619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 8629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 8630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 867313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 868313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 869313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 8709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 8710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 8720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 87977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 88077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 886c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 889c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 890f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false), 891f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(value), Loc(l), IsWide(iswide) { 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8930b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 8940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 8950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 8960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 897018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 898c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 9011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 9050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 9060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 9070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 91277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 91377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 91477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 91577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 9199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 920720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 9229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 924720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 925f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false), 9269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 9279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 9289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 93017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 9329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 93317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 9349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 9359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 9369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 9379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 9389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 9409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 9419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 9429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 94317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 944720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 94517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 946c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 947da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 948da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 949da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 950da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 95317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 95417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 96377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9675d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 9685d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 9695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 9705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 9715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 9725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 9735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 9745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 9755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 976f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false), 977f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 979cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 981cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 982cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 9835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 9845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 985cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 986cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 9875d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 9905d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 9915d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9935d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 9945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_begin(); 9955d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner virtual child_iterator child_end(); 9965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 9975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 998e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 999e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1000e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1001a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1002c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1003c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1004690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1005690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 10068bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1007690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1008c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1009c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1010c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1011c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1012c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1013c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 1018726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 1019726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 10202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1021f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1022f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false) {} 10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 10262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 10272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static StringLiteral *Create(ASTContext &C, const char *StrData, 10282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, QualType Ty, 1029a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 10302085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 10312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static StringLiteral *Create(ASTContext &C, const char *StrData, 10332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, 10342085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner bool Wide, QualType Ty, SourceLocation Loc) { 10352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 10362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1037a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1038673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1039673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1040673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1041b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1042b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1043b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 10442f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1046673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1047673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1048b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1049673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 1051673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void setWide(bool W) { IsWide = W; } 1052673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 10538d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1054b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1055b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1056b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 105733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 105833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 105933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1060726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1061726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1062726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1064726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1065726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1066726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1067726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1069673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1070673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1071673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 107208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 107308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 107408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 107508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 107608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 107708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 107808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 107908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 108008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 108108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 108208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1083673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1084b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1085b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1086b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 109777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 109877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 11055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1109f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump val->isTypeDependent(), val->isValueDependent()), 1111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1113c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1115c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1116c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 11175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 11185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1119c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1120c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 1121866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1123313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1124313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1125c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1126313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1127313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1128313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1129c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1130313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 11311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 113777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 113877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 11430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1145dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1146dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1147dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1148dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1149dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1150dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1151dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 11525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11545baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 11555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 11570799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11590799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1163f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1165de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump input->isValueDependent()), 11670799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 11712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 11720b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11730799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 11740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 11750b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 11770b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 11780b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 11810b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 11820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 11842085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 11852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 11862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1188cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 11892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 11902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 11912085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 11925a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 11930799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 11940799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 11952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1196993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 11972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 11982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1199993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 12002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 12012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 12022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 12032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 12040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1210bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1211bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1212bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1213bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1214bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1215bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1216bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1217bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return Loc; } 12251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 123177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 123277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 123377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 12388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 12398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 12408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1241c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 12428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 12438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 12448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 12458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 12468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 12478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1248c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 12498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 12518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 12528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 12538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 12548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 12558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 12568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1257cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 12588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1259cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 12608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1261cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1262cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1263cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1264cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1265cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 12668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1270c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 12728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1273c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 12758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1276c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 12778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 12788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 12798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 12808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1281c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1282cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 12838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1284c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 12868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1287c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 12888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 12898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1290c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1294c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1296c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1300c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1302cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1303cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1304cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1305cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 13098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 13138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 13148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 13158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 13168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 13178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 13218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1322cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 13278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1328c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1329cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1330cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1331cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1332c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1333cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1334c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 13368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 13378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 13388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1339c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 13408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 13418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange getRange() const { return Range; } 13428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 13438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1345c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 13478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 13488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 13498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 13508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 13518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 13528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1353c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1356c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 13578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 13598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1365c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1366c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1372c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 13848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 13858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 13878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 13888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 13908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const OffsetOfNode &getComponent(unsigned Idx) { 13918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 13938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 13978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 14058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 14068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 14078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 14088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 14118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 14128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 14138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 14148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1415c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 14178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 14188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual SourceRange getSourceRange() const { 14218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 14228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 14268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 14298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 14318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_begin(); 14328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor virtual child_iterator child_end(); 14338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 14360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions. 14370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr { 14380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isSizeof : 1; // true if sizeof, false if alignof. 14390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1440d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1441a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1442d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1443d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 144542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1447a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 14480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType resultType, SourceLocation op, 14490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl SourceLocation rp) : 1450f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary, 1451ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 14522850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1453a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TInfo->getType()->isDependentType()), 1454ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1455a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1456ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1457ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SizeOfAlignOfExpr(bool issizeof, Expr *E, 1459ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor QualType resultType, SourceLocation op, 1460ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor SourceLocation rp) : 1461f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary, 1462ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1463ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1464ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor E->isTypeDependent()), 1465ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1466ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1467d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 14680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 14690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 14700b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor explicit SizeOfAlignOfExpr(EmptyShell Empty) 14710b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor : Expr(SizeOfAlignOfExprClass, Empty) { } 14720b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSizeOf() const { return isSizeof; } 14740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSizeof(bool S) { isSizeof = S; } 14750b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 14770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 14785ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 14795ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1480a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 14810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 14825ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 14830518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1484caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 14850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1486d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 14870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1488caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1489caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1490caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 14910b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14920b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1493a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1494a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 14960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 14970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14980518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 14990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 15000518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 15010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 15020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 15030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 150476e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 15050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 15060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15070b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 15080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1509866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1510866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek virtual SourceRange getSourceRange() const { 1511866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1512866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == SizeOfAlignOfExprClass; 15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl static bool classof(const SizeOfAlignOfExpr *) { return true; } 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 151977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 152077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 152177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 153077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 15335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15342324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1535f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 153673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1537f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 15382850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 15392850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isValueDependent() || rhs->isValueDependent()), 15402850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 154173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 154273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 154373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1545cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1546cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1547cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1548cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 15492324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 15502324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 15512324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 15522324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 15532324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 155433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 155533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 155633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 155733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 15585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 15595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1560cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1561cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 15625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 15635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1564cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 15675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 156877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 15715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 15722324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 15755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 15762324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 15795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 158377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1586026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1587cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1588cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 15895cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 159677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 159777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 159877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1602b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1604b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1606b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1607b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 160977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { FN=0, ARGS_START=1 }; 16105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1614b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1615b4609806e9232593ece09ce08b630836e825865cDouglas Gregor // This version of the constructor is for derived classes. 1616668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1617f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc); 161842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 16195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1621f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16231f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1624ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 16251f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 16265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 16275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 162818b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1629a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1630d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1631d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1632d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1633d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1634d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1635a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1636a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1637bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1638bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1639bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1640a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 16415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 16485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 16525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Arg+ARGS_START]); 16535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1655934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1656934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1657934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1658934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff SubExprs[Arg+ARGS_START] = ArgExpr; 1659934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1661d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1662d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1663d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 16648189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 16675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1669d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1670d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 16715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 16725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 16765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 16775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1678cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1679cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 16803c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned isBuiltinCall(ASTContext &Context) const; 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 16831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 16846dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 16856dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1687d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 16881f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1689866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual SourceRange getSourceRange() const { 169177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getCallee()->getLocStart(), RParenLoc); 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16954bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 16964bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 169988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 170077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 170177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_begin(); 170277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek virtual child_iterator child_end(); 17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1705ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 17086bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 17096bb8017bb9e828d118e15e59d71c66bba323c364John McCall struct MemberNameQualifier : public NameQualifier { 1710161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 17116bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 17126bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1713ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1714ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 17155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1717ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1718ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1719f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1721ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 17225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 17252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 17262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 17272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 1728ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 172983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 17326bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 17336bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 1734c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 17356bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1737c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 1738c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1739c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 1740c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 17416bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 1742c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 174483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 17456bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 17466bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 17476bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 174883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 174983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 175083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 17516bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 1752c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1753c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1756f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1757f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 1758f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1759f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 17602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara base->isTypeDependent(), base->isValueDependent()), 17612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 17622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 17632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 17642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 17652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 17662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 17672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 17682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 17692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 17702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 17712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1772f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 1773f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 1774f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 1775ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson base->isTypeDependent(), base->isValueDependent()), 17762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 17772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 17786bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1779510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 178183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, SourceRange qualrange, 1782161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 17832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 1784d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 1785f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 178788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 17885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 178957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 179057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 179157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 179257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 179357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 1794f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 1795f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 17961f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 17976bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 1798161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 17996bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 1800161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 1801161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 18026bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 18036bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 18046bb8017bb9e828d118e15e59d71c66bba323c364John McCall 18051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 18060979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 18070979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 18086bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 18091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief If the member name was qualified, retrieves the source range of 181183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// the nested-name-specifier that precedes the member name. Otherwise, 181283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// returns an empty source range. 18131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceRange getQualifierRange() const { 18146bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 181583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return SourceRange(); 18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->Range; 181883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 182183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 182283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 18246bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 182583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return getMemberQualifier()->NNS; 182883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 1829c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 1830c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 1831c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 1832096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 18331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 1834c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1836d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1837d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1838d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1839096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1840096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1841096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1842096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1843096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1844096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 1845096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 1846096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1847096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 1848096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 1849096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1850096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1851096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 1852096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 1853096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1854096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1855096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 1856096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 1857096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 1858096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1859096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 1860096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 1861096832c5ed5b9106fa177ebc148489760c3bc496John McCall 1862096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 1863096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 1864096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 1865096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 1866096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 1867096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 1868d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 1869c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 18701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 1871c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 1873c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1874c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1876096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 1877c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1879c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 1880c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 1881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1882c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1885096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 1886c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1888c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1889c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 1891c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1894096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1895c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 1898c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 1900c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 1901c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 19021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1903096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 1904c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 19051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 19072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 19082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 19092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 19102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 19112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 19125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 19131f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 19141f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 1915ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 1916ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 1917026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 19181f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 192172527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // If we have an implicit base (like a C++ implicit this), 192272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman // make sure not to return its location 19232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation EndLoc = (HasExplicitTemplateArgumentList) 19242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ? getRAngleLoc() : getMemberNameInfo().getEndLoc(); 19251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 192672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman SourceLocation BaseLoc = getBase()->getLocStart(); 192772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman if (BaseLoc.isInvalid()) 1928c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(MemberLoc, EndLoc); 1929c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceRange(BaseLoc, EndLoc); 19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceLocation getExprLoc() const { return MemberLoc; } 19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 193583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19391237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 19401237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 19411237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 19424045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 19434045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 19444045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 1948aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 1949aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 19500fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 19510fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 19520fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 19530fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 19541d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 19551d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 19561d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 195742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 19585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 1959e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 1960aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 19612333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can compound literals be value-dependent? 196242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 1963f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 1964f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 196542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall tinfo->getType()->isDependentType(), false), 196642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 19671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1968ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 1969ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 1970ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 1971ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 19725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 19735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 1974ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 1975e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 1976e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 1977ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 1978ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 19790fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 1980ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1981ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 198242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 198342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 198442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 198573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner virtual SourceRange getSourceRange() const { 19860fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 19870fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 19880fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 19890fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 199073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 19910fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 199273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 1993aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 1996aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 1997aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 19981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19991237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 20001237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 20011237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2002aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2003aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 200449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 200549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 200649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 200749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 20080835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2009cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 20105baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 20111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2012cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 20130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2014409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2015daa8e4e888758d55a7a759dd4a91b83921cef222John McCall void CheckCastConsistency() const { 2016409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2017409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 20185cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2019cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2020cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2021409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2022409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2023f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2024f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2025409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2026409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2027409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2028409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2029409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2030409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2031409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2032409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2033404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 2034409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2035409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2036409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2037409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2038409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2039409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2040409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2041409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2042409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2043409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2044409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2045569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 20462bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 2047f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 20482bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 2049f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 20502bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 2051f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 20522bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 2053f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 2054daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 2055daa8e4e888758d55a7a759dd4a91b83921cef222John McCall // fallthrough to check for null base path 2056daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 2057daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 2058daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_NoOp: 2059daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 2060daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 2061daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 2062daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_MemberPointerToBoolean: 2063daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingComplexToBoolean: 2064daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralComplexToBoolean: 20655082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_LValueBitCast: // -> bool& 20665082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_UserDefinedConversion: // operator bool() 2067f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2068409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2069409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2070409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2071409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2072409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2073f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2074f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2075f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2076f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2077f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 20780835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2079f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2080f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2081f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2082898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2083898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2084898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2085898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2086898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ty->isDependentType() || (op && op->isValueDependent())), 20888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2089daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 20908e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 20918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 2092daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 2093f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 20941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2095087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2096f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 20978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 20988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.BasePathSize = BasePathSize; 20998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 21028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 21038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2104f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2105f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 21060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 21070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2108087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2109087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 21106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 21116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 21126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 21136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 21146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 21156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 21166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 211741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2118f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2119f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 21208e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 21218e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2122f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2123f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2124f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2125f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2126f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2127f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 212841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21304bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 21314bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 21320835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 21330835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21350835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 21360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_begin(); 21370835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual child_iterator child_end(); 21380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 21390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 214049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 214149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 214249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 214349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 214449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2145bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2146bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2147906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2148bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2149bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2150bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2151bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2152906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 21531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2154906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2155906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2156906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2157906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2158bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2159bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 21600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2161906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2162f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 21635baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 21655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 216690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2167087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2168f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2169f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2170f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2171f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2172f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2173f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 21745baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2175f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 21765baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2177f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2178f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2179f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2180f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 21815baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2182f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2183f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2184087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 21850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis virtual SourceRange getSourceRange() const { 21860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 21870835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 218890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 219149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 219249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 219349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 219449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 219549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 219749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 219849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 219949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 220049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 220149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 220249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 22035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 220449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 220549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 220649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 220749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 220849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2209906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2210906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 22110835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 22129d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 22139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 22149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 221549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 221649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2218f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2219f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2220f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 222149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2222db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2223f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2224f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2225db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 222649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 22279d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 22289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 22299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 22309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 22319d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 223249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 223349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 22349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 223549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22374bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 22384bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 223949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 224049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 224149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 224249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 22436eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 224449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 224549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 22466eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2247b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2248b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2250f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 225241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2253f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 225441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 225549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2256db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2257f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2258f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2259f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2260f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2261f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2262f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2263f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2264f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2265f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2266f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2267f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2268db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2269b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2270db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2271db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2272b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2273db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2274db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 22755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 2276b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 22805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22816eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 22825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 22853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 22873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 22883fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 22893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 22903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 22913fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 22923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 22933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 22943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 22953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 22963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 22973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 22983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 22993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 23003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 23013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 23025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 23035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 23045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 23055baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 230617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 23070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 23080799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 23090799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 231017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 23115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 23121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 23131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 231417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 231617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump lhs->isValueDependent() || rhs->isValueDependent()), 2320898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 23211237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 23221237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 23245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 23255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2327db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 23292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2330db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 233117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2332db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2333db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2335db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2336db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2338db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 23395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2340db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2341db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 23425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 23445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23500799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2351a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2352063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2353063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2354063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2355063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2356063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2357063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2358063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2359063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 23605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2361200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 23622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 23632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 23640799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 23652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 23660799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2367aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 23682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 23690799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2370f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 23720799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2373f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 23750799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 23780799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2379aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 23802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 23810799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2382f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 23832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isAssignmentOp() const { return Opc >= BO_Assign && Opc <= BO_OrAssign; } 23842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isCompoundAssignmentOp() const { 23852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 23862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 23872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isShiftAssignOp() const { 23882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 23892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 23901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 23924bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 23934bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 23961237c673c07f9d827129ba02720108816abde562Ted Kremenek 23971237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 23981237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 23991237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 24001237c673c07f9d827129ba02720108816abde562Ted Kremenek 24015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 240217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2403f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 24042333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 24062333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 24072333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isValueDependent() || rhs->isValueDependent()), 24082333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 24091237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24101237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 24115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2412ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 24142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 24155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 24185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 24195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 24205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 24215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 24235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2424ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2425ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 24265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2428f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2429f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 243017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2431f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2432ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2433ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 24341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 24355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 24365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2438ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2439ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2440ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2441ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2442ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2443ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2444ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2445ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2446ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2447ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2448ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2449ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2450ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 24515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 24545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 24585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use. 24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr { 24611237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 24625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2463f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Stmt* Save; 246447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation QuestionLoc, ColonLoc; 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 246647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 2467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation CLoc, Expr *rhs, Expr *save, 24680943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 24690943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ConditionalOperatorClass, t, VK, OK, 2470898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2472898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 2473898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 24741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (cond->isValueDependent() || 2475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor (lhs && lhs->isValueDependent()) || 247647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor (rhs && rhs->isValueDependent()))), 247747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor QuestionLoc(QLoc), 247847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ColonLoc(CLoc) { 24791237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 24801237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 24811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 2482f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Save = save; 24831237c673c07f9d827129ba02720108816abde562Ted Kremenek } 24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2485ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2486ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 2487ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : Expr(ConditionalOperatorClass, Empty) { } 2488ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2489395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 2490395a2abf0028968d85958610e393e067885dc14fTed Kremenek // the ?: operator. 24915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2492ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 2493395a2abf0028968d85958610e393e067885dc14fTed Kremenek 2494395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getTrueExpr - Return the subexpression representing the value of the ?: 2495f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // expression if the condition evaluates to true. 2496395a2abf0028968d85958610e393e067885dc14fTed Kremenek Expr *getTrueExpr() const { 2497af9b96828f9126d993c3e155b8453be62013b735Fariborz Jahanian return cast<Expr>(SubExprs[LHS]); 2498395a2abf0028968d85958610e393e067885dc14fTed Kremenek } 24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2500ae2777cfe7d21f73e5a4155082fe20197cec62bdNick Lewycky // getFalseExpr - Return the subexpression representing the value of the ?: 2501395a2abf0028968d85958610e393e067885dc14fTed Kremenek // expression if the condition evaluates to false. This is the same as getRHS. 25025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2503f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 2504f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // getSaveExpr - In most cases this value will be null. Except a GCC extension 2505f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // allows the left subexpression to be omitted, and instead of that condition 2506f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // be returned. e.g: x ?: y is shorthand for x ? x : y, except that the 2507f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // expression "x" is only evaluated once. Under this senario, this function 2508f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian // returns the original, non-converted condition expression for the ?:operator 2509f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getSaveExpr() const { return Save? cast<Expr>(Save) : (Expr*)0; } 2510f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 2511f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getLHS() const { return Save ? 0 : cast<Expr>(SubExprs[LHS]); } 2512ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2513ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 25145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2515ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 25165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2517f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian Expr *getSAVE() const { return Save? cast<Expr>(Save) : (Expr*)0; } 2518f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian void setSAVE(Expr *E) { Save = E; } 2519f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 252047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getQuestionLoc() const { return QuestionLoc; } 252147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 252247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 252347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor SourceLocation getColonLoc() const { return ColonLoc; } 252447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor void setColonLoc(SourceLocation L) { ColonLoc = L; } 252547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 25265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 25275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 25285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 25315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 25331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25341237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25351237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25361237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 25375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25396481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 25406481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 25415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 25425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *Label; 25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25446481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 25456481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2546f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false), 25472333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 25481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 25517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 25527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 25547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 25557d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 25567d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 25577d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual SourceRange getSourceRange() const { 25595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 25605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LabelStmt *getLabel() const { return Label; } 25637d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabel(LabelStmt *S) { Label = S; } 25647d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 25655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 25661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 25675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25686481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 25691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25701237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 25711237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 25721237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2574ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2575ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2576ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2577ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2578f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 2579f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 2580f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 2581ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 25825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2583ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2584ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 25852333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2586d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2587d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2588f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 2589f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall T->isDependentType(), false), 25902333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 25911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25926a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 25936a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 25946a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 25955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 25965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 25976a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 25986a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 2599ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner virtual SourceRange getSourceRange() const { 2600ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2601ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 26021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2603026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 26046a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2605026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 26066a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 26071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2608ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 2610ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 2611ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 26121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26131237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 26141237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 26151237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2616ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 2617ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2618dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2619d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not 2620d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be 2621d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions. 2622d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr { 26233fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo1; 26243fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *TInfo2; 2625363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2626d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic: 26271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 26283fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2, 26293fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara SourceLocation RP) : 2630f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(TypesCompatibleExprClass, ReturnType, VK_RValue, OK_Ordinary, 2631f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall false, false), 26323fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TInfo1(tinfo1), TInfo2(tinfo2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2633d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 263444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_type_compatible_p expression. 263544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit TypesCompatibleExpr(EmptyShell Empty) 263644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor : Expr(TypesCompatibleExprClass, Empty) { } 263744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 26383fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo1() const { return TInfo1; } 26393fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; } 26403fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara TypeSourceInfo *getArgTInfo2() const { return TInfo2; } 26413fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; } 26423fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara 26433fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType1() const { return TInfo1->getType(); } 26443fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara QualType getArgType2() const { return TInfo2->getType(); } 26451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 264644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 264744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 26481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 264944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 265044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2652d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff virtual SourceRange getSourceRange() const { 2653363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2654d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2655d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const Stmt *T) { 26561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == TypesCompatibleExprClass; 2657d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff } 2658d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff static bool classof(const TypesCompatibleExpr *) { return true; } 26591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26601237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 26611237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 26621237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2663d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff}; 2664d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 2665d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 2666d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 2667d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 2668d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 2669d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 2670d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 2671d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 2672d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 2673d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2674d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 2675d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 2676d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 2677d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 26785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 2679d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 2680d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2681d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 26822333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 26832333f7727f97018d6742e1e0938133bcfad967abEli Friedman // to be computed differently? 2684a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 26851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 26861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation RP) : 2687f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 2688f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Type->isDependentType(), false), 26892333f7727f97018d6742e1e0938133bcfad967abEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 26901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2691a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman SubExprs = new (C) Stmt*[nexpr]; 2692d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman for (unsigned i = 0; i < nexpr; i++) 2693d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SubExprs[i] = args[i]; 2694d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 269594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 269694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 26971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 269894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 269994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 270094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 270194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 270494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 270594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual SourceRange getSourceRange() const { 2707d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 2708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 27101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 2711d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 27131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2714d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 2716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 2717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 27181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 2720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 2721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 27225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2723d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 2724d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 2725d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 27265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 2727d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2729888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 273094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 2731dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2732dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 27339a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2734d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2736d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 2737d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_begin(); 2738d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman virtual child_iterator child_end(); 2739d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 2740d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 2741d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 27421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 2743d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 27447976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 27457976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 27467976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 27477976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 27487976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 27497976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 2750d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 27511237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 27525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2753d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 2754d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 2755f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 2756f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 2757ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 2758f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent), 27591237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 27601237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 27611237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27621237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27647976932a1c256d447316ffac58e9821417725e34Eli Friedman 276544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 276644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 276744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 27687976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 27697976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 277027437caadea35f84d550cd29f024fcf3ea240eecChris Lattner bool isConditionTrue(ASTContext &C) const; 27717976932a1c256d447316ffac58e9821417725e34Eli Friedman 27727976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 27737976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 27747976932a1c256d447316ffac58e9821417725e34Eli Friedman Expr *getChosenSubExpr(ASTContext &C) const { 27757976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 27767976932a1c256d447316ffac58e9821417725e34Eli Friedman } 27777976932a1c256d447316ffac58e9821417725e34Eli Friedman 27785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 277944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 27805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 278144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 27825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 278344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 278444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 278544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 278644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 278944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 27901237c673c07f9d827129ba02720108816abde562Ted Kremenek 2791d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff virtual SourceRange getSourceRange() const { 2792d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 2793d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2794d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 2796d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 2797d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 27981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27991237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 28001237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_begin(); 28011237c673c07f9d827129ba02720108816abde562Ted Kremenek virtual child_iterator child_end(); 2802d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 2803d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 28042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 28052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 28062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 28072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 28082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 28092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 28102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 28112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 28122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 28132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 28142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 28151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 2816f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false), 2817f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 28182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 281944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 282044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 282144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 28222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 28232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 282444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 28252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 28262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual SourceRange getSourceRange() const { 28272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 28282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 28292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 28312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 28322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 28331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 28352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_begin(); 28362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor virtual child_iterator child_end(); 28372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 28382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 283974626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 28407c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 28415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 28422cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 28437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 28447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 28452cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 28462cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 2847f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 2848f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall t->isDependentType(), false), 28492cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 28507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 28517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 28521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 285374626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 2854d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2855d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 28575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 2858d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 2859d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28602cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 28612cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 28622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 2863d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2864d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 28651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2866d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2867d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2868d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 28697c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual SourceRange getSourceRange() const { 28707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 28711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 28737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 28747c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 28757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28777c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 28787c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson virtual child_iterator child_begin(); 28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 28807c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 28811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 28834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 28854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 28864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 28874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 28884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 28894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 28904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 2891196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 28924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 28934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 28944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 28954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 28964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 28974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 28984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 28994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 2900196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 29014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 29024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 29034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 29044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 29054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 29064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 29074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 29083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 29094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 29104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 29114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 2912196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 29134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 29144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 29154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 29164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 29174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 29184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 291966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 2920ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 2921709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 2922709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 292366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 29241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 29264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 29274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 29284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 29290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// If this initializer list initializes a union, specifies which 29300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// field within the union will be initialized. 29310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *UnionFieldInit; 29320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2933a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 2934a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 2935a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 2936a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 293766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 2938709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 2939709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 2940ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 2941d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2942d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 2943709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 2944709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 29451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2946ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 294816c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 2949c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 295166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 295316c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 2954c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 295666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 29571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 2959c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 29609e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 29619e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 2962c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 2963fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 2964709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 29651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 29674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 29694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 29704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 29714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 29724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 29734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 29744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 29754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 29764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 29774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 29784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 29794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 29804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// accomodate the new entry. 2981709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 2982c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 29830bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 29840bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 29850bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 29860bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 29870bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 29880bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 29890bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 29900bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 29910bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 2992c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 2993c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 2994b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 2995b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 2996b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 29971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2998d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 2999d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3000d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 300187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 300287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 30034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 30044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 30054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 30074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 30084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 30094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3010a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 30111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3012d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3013a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3014a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 3015c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek virtual SourceRange getSourceRange() const; 3016c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 301766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 301966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 302066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 30211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 302266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 302366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_begin(); 302466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson virtual child_iterator child_end(); 30251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3026709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 30278111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3028709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 30298111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 30301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3031ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 30328111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3033ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 30348111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3035ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 30368111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3037ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 30388111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 303966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 304066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 304105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 304205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 30481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 305605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 305905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 306005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3062ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3063ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3064ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3065ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3066ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 306705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 306805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 306905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 307005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3071eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 307205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3073eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 307405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 307505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 307605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 307705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3078ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3079ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3080ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3081ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 308505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3087ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3088319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3089ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3090eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 30919ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 30929ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3094d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3095d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3096d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3097d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 310305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 310405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 310505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 310605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 310705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 31081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 31111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 311905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 312005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 312105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 312605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 312805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 312905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 313005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 313105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 313205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 313305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 313505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 313605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 313705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 314405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 314505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 314605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 314705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 314805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 314905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 315005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 315105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 315205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3153ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3154ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 315505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 31561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 31571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 315905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 316005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 316205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 31651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 316805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 316905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 317205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 31751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 317805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 317905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 318005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 318105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor IdentifierInfo * getFieldName(); 318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDecl *getField() { 319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 319405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 319505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 319705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 319805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 319905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 320005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 320105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 320387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 320487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 320587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 320687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 320787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 320805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 320905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 321005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 321105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 321205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 321305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 321405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 321505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 321605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 321705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 321805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 321905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 322005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 322105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 322205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 322405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 322505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 322605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 322705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 322805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 322905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 32304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3231d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3232d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3233d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3234d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3235d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3236d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 32374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 32384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 32394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 32404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 32414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 32424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 324305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 324405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 324605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 324705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 324805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3249eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 325005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3251d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3252d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 325305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 325405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 325505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 325605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 325705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor typedef Designator* designators_iterator; 3258ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 32591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 32601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3261ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 326205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3263cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3264cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3265cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3266cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3267cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3268cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3269cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3270cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3271cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3272711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3273711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3274c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3275319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3276d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 327705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 327805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 327905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 328005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 328105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 328205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 328305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3284d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 328505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 328605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3287eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3288eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3289d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 329005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 329105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 32921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 329305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 329405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 329505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 329605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 329705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 329805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 329905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3300d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3301d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3302d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3303d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3304d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3305d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3306d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3307d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3308d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3309d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3310d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3311d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3312d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3313d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3314d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3315d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3316d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3317d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3318d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3319d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3320ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3321ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3322319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3323ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3324ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 332505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual SourceRange getSourceRange() const; 332605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 332705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 33281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 332905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 333005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 333105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 333205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 333305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor virtual child_iterator child_begin(); 33341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 33353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 33363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33373498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 33383498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 33393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 33401a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 33411a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 33423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 33431a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 33441a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 33451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 33463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 33471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3348f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall false, false) { } 33503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3351d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3352d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3353d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3354d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 33551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 33563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 33573498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 33583498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 33593498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33603498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual SourceRange getSourceRange() const { 33613498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 33623498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 33633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 33643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 33653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor virtual child_iterator child_begin(); 33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual child_iterator child_end(); 336705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 336805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 33692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 33712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 33722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 33732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 33742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 33761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 33772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned numexprs, SourceLocation rparenloc); 33782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 338037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 33811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 33831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 33852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 33862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 33872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 33902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 33912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 33922ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 33932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 339483ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 33951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 33972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 33982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 33992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual SourceRange getSourceRange() const { 34002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 34022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 34031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 34042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 34052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 34061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 34082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_begin(); 34092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman virtual child_iterator child_end(); 341037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 341160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 34123397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 34132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 34142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 34151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 34174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 34184eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 34194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3420a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3421a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3422a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3423a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3424a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 342573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 342673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 342773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3428a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3429a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3430d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3431a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3432a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3433f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 3434f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 34350943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 34360943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 3437f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall base->isTypeDependent(), base->isValueDependent()), 3438d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 34391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3440d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3441d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3442d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3443d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3444a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3445a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3446d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3447d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3448d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3449d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3450d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3451d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3452d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3453d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3454a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3455a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3457a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3458a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3459a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 34601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3461a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3462a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3463a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 34641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3465a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual SourceRange getSourceRange() const { 3466a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3467a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 34681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34692140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 34702140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 34712140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 34721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 34741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3475a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3476a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 34771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3478a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 3479a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_begin(); 3480a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner virtual child_iterator child_end(); 3481a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3482a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3483a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 348456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 34859c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 34864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 348756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 348856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 3489b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool HasBlockDeclRefExprs; 34904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 3491b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 3492f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 3493f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty->isDependentType(), false), 3494b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 34959c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 349684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 349784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 349884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 3499d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 350056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 350184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 350284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 350356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 350456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 350556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 350656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 35079c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 35089c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff virtual SourceRange getSourceRange() const { 350956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 35109c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 35119c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 351256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 351356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 351456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 3515b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 35165b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner /// inside of the block that reference values outside the block. 3517b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 351884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3519b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump 35201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 35219c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 35224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 35234eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 35241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35254eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 35264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 35274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 35284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 35291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function, 35314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc. 35324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 35331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDecl *D; 35344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 35357d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 35367d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 353789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Stmt *CopyConstructorVal; 35384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 35392333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Fix type/value dependence! 3540f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall BlockDeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, 3541f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, bool ByRef, bool constAdded = false, 354284ca008a462b515f63871253f494d53c9190363cFariborz Jahanian Stmt *copyConstructorVal = 0) 3543f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, 3544f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall (!t.isNull() && t->isDependentType()), false), 354552bc56a296b11b4fc6bf5ddf4ded5262f6484bdbFariborz Jahanian D(d), Loc(l), IsByRef(ByRef), 354689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian ConstQualAdded(constAdded), CopyConstructorVal(copyConstructorVal) {} 354794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 354894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 354994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 355094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 355194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 35521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff ValueDecl *getDecl() { return D; } 35544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff const ValueDecl *getDecl() const { return D; } 355594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setDecl(ValueDecl *VD) { D = VD; } 355694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 355794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 355894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 355994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 35604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 35611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 356394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 35641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35657d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 35667d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 356789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 356889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian const Expr *getCopyConstructorExpr() const 356989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 357089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian Expr *getCopyConstructorExpr() 357189f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian { return cast_or_null<Expr>(CopyConstructorVal); } 357289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; } 357394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 35741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 35751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 35764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 35774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 35781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35794eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 35804eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_begin(); 35814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff virtual child_iterator child_end(); 35824eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 35834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 35847cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 35857cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// fixed type and value class. These don't correspond to concrete 35867cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// syntax; instead they're used to express operations (usually copy 35877cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// operations) on values whose source is generally obvious from 35887cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// context. 35897cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallclass OpaqueValueExpr : public Expr { 35907cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall friend class ASTStmtReader; 35917cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallpublic: 3592f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall OpaqueValueExpr(QualType T, ExprValueKind VK, ExprObjectKind OK = OK_Ordinary) 3593f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 3594f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall T->isDependentType(), T->isDependentType()) { 35957cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall } 35967cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 35977cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall explicit OpaqueValueExpr(EmptyShell Empty) 35987cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall : Expr(OpaqueValueExprClass, Empty) { } 35997cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 36007cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall virtual SourceRange getSourceRange() const; 36017cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall virtual child_iterator child_begin(); 36027cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall virtual child_iterator child_end(); 36037cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 36047cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall static bool classof(const Stmt *T) { 36057cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return T->getStmtClass() == OpaqueValueExprClass; 36067cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall } 36077cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall static bool classof(const OpaqueValueExpr *) { return true; } 36087cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall}; 36097cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 36105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 36115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 36125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3613