Expr.h revision 2c9a03f3b249e4d9d76eadf758a33142adc4d0a4
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"
28403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype>
29c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
32590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
33c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
378e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
40409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CXXBaseSpecifier;
4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
43f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  class ObjCPropertyRefExpr;
44833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
45d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers.
48f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
57bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  virtual void ANCHOR(); // key function.
585baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected:
60f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
61bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor       bool TD, bool VD, bool ContainsUnexpandedParameterPack) : Stmt(SC) {
628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.TypeDependent = TD;
638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.ValueDependent = VD;
64f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    ExprBits.ValueKind = VK;
65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    ExprBits.ObjectKind = OK;
66bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
74f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
83905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
848320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
85f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
8877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool isValueDependent() const { return ExprBits.ValueDependent; }
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setValueDependent(bool VD) { ExprBits.ValueDependent = VD; }
1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
1128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool isTypeDependent() const { return ExprBits.TypeDependent; }
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setTypeDependent(bool TD) { ExprBits.TypeDependent = TD; }
1160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this expression contains an unexpanded parameter
118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack (for C++0x variadic templates).
119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Given the following function template:
121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename F, typename ...Types>
124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// void forward(const F &f, Types &&...args) {
125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   f(static_cast<Types&&>(args)...);
126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// }
127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// The expressions \c args and \c static_cast<Types&&>(args) both
130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain parameter packs.
131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return ExprBits.ContainsUnexpandedParameterPack;
133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
135bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// \brief Set the bit that describes whether this expression
136bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// contains an unexpanded parameter pack.
137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
138bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    ExprBits.ContainsUnexpandedParameterPack = PP;
139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  }
140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
151026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
152026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
153026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
154026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
155df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                              SourceRange &R2, ASTContext &Ctx) const;
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1577eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// isLValue - True if this expression is an "l-value" according to
1587eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// the rules of the current language.  C and C++ give somewhat
1597eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// different rules for this concept, but in general, the result of
1607eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// an l-value expression identifies a specific object whereas the
1617eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// result of an r-value expression is a value detached from any
1627eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// specific storage.
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// C++0x divides the concept of "r-value" into pure r-values
1657eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// ("pr-values") and so-called expiring values ("x-values"), which
1667eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// identify specific objects that can be safely cannibalized for
1677eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// their resources.  This is an unfortunate abuse of terminology on
1687eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// the part of the C++ committee.  In Clang, when we say "r-value",
1697eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// we generally mean a pr-value.
1707eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isLValue() const { return getValueKind() == VK_LValue; }
1717eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isRValue() const { return getValueKind() == VK_RValue; }
1727eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isXValue() const { return getValueKind() == VK_XValue; }
1737eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isGLValue() const { return getValueKind() != VK_RValue; }
1747eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall
1757eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  enum LValueClassification {
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
179fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
18086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
1812514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    LV_MemberFunction,
182e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    LV_SubObjCPropertySetting,
183e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    LV_ClassTemporary
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1857eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// Reasons why an expression might not be an l-value.
1867eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
18753202857c60214d80950a975e6e52aebf30bd16aEli Friedman
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and if it is a structure or union, does not have any member (including,
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
19344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
19444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
19544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
19644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
201fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
203ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
2064f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
2075daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
208ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
20986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
2102514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    MLV_MemberFunction,
211e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    MLV_SubObjCPropertySetting,
212e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    MLV_ClassTemporary
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
21444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
21544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief The return type of classify(). Represents the C++0x expression
2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        taxonomy.
2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  class Classification {
2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The various classification results. Most of these mean prvalue.
2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum Kinds {
2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_LValue,
2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_XValue,
2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Function, // Functions cannot be lvalues in C.
2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Void, // Void cannot be an lvalue in C.
2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_MemberFunction, // An expression referring to a member function
2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_SubObjCPropertySetting,
2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_ClassTemporary, // A prvalue of class type
2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_PRValue // A prvalue for any other reason, of any other type
2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The results of modification testing.
2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum ModifiableType {
2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Untested, // testModifiable was false.
2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Modifiable,
2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_RValue, // Not modifiable because it's an rvalue
2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Function, // Not modifiable because it's a function; C++ only
2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NotBlockQualified, // Not captured in the closure
2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ConstQualified,
2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ArrayType,
2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_IncompleteType
2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  private:
2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    friend class Expr;
2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Kind;
2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Modifiable;
2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    explicit Classification(Kinds k, ModifiableType m)
2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      : Kind(k), Modifiable(m)
2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    {}
2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Classification() {}
2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Kinds getKind() const { return static_cast<Kinds>(Kind); }
2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    ModifiableType getModifiable() const {
2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      return static_cast<ModifiableType>(Modifiable);
2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    }
2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isLValue() const { return Kind == CL_LValue; }
2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isXValue() const { return Kind == CL_XValue; }
2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isGLValue() const { return Kind <= CL_XValue; }
2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isPRValue() const { return Kind >= CL_Function; }
2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isRValue() const { return Kind >= CL_XValue; }
2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
2712c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
2722c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    /// \brief Create a simple, modifiably lvalue
2732c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    static Classification makeSimpleLValue() {
2742c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor      return Classification(CL_LValue, CM_Modifiable);
2752c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    }
2762c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
278369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief Classify - Classify this expression according to the C++0x
2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        expression taxonomy.
2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// old lvalue vs rvalue. This function determines the type of expression this
2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// is. There are three expression types:
2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - lvalues are classical lvalues as in C++03.
2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - prvalues are equivalent to rvalues in C++03.
2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///   function returning an rvalue reference.
2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// lvalues and xvalues are collectively referred to as glvalues, while
2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// prvalues and xvalues together form rvalues.
2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification Classify(ASTContext &Ctx) const {
2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, 0);
2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
294369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief ClassifyModifiable - Classify this expression according to the
2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        C++0x expression taxonomy, and see if it is valid on the left side
2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        of an assignment.
2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// This function extends classify in that it also tests whether the
2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// expression is modifiable (C99 6.3.2.1p1).
3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \param Loc A source location that might be filled with a relevant location
3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///            if the expression is not modifiable.
3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, &Loc);
3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getValueKindForType - Given a formal return or parameter type,
307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// give its value kind.
308f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static ExprValueKind getValueKindForType(QualType T) {
309f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    if (const ReferenceType *RT = T->getAs<ReferenceType>())
3100943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      return (isa<LValueReferenceType>(RT)
3110943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                ? VK_LValue
3120943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                : (RT->getPointeeType()->isFunctionType()
3130943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                     ? VK_LValue : VK_XValue));
314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return VK_RValue;
315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getValueKind - The value kind that this expression produces.
318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExprValueKind getValueKind() const {
319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return static_cast<ExprValueKind>(ExprBits.ValueKind);
320f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getObjectKind - The object kind that this expression produces.
323f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// Object kinds are meaningful only for expressions that yield an
324f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// l-value or x-value.
325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExprObjectKind getObjectKind() const {
326f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
327f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
328f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// setValueKind - Set the value kind produced by this expression.
330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
331f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
332f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// setObjectKind - Set the object kind produced by this expression.
333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate:
3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic:
3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
34033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
34133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
34233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
34438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
34538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
34638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
348f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// \brief If this expression is an l-value for an Objective C
349f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// property, find the underlying property reference expression.
350f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  const ObjCPropertyRefExpr *getObjCProperty() const;
351f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall
352093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
353093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  bool refersToVectorElement() const;
354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
3562b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
3572b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// but also int expressions which are produced by things like comparisons in
3582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// C.
3592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isKnownToHaveBooleanValue() const;
360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
365590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
366590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
368590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
3698070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
370590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
372c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
373c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
3744204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
3751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
37794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
3782d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
37994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
38294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
38394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
38694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
38794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
38894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
38994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
39094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
39194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
39294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
39394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
39494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
39594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
398e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
399e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // isGlobalLValue - Return true if the evaluated lvalue expression
400e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // is global.
401e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool isGlobalLValue() const;
402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // hasSideEffects - Return true if the evaluated expression has
403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // side effects.
404e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool hasSideEffects() const {
405e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara      return HasSideEffects;
406e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    }
40794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
40894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
4096ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
410019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
411019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
412019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
4134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const;
4145b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
415cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// EvaluateAsBooleanCondition - Return true if this is a constant
416cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// which we we can fold and convert to a boolean condition using
417cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// any crazy technique that we want to.
4184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
419cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
4206ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
42145b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
4224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool isEvaluatable(const ASTContext &Ctx) const;
423c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
4246ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// HasSideEffects - This routine returns true for all those expressions
425138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif  /// which must be evaluated each time and must not be optimized away
4266ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// or evaluated at compile time. Example is a function call, volatile
4276ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// variable read.
4284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool HasSideEffects(const ASTContext &Ctx) const;
429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
43051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
43151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
4324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const;
43351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
434b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
435b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// with link time known address.
4364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
4371b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
438e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
4394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const;
440e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
441ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
442ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// should cope with value-dependent expressions.
443ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  enum NullPointerConstantValueDependence {
444ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
445ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_NeverValueDependent = 0,
446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
447ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression of integral or
448ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// dependent type should be considered a null pointer constant.
449ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNull,
450c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
451ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression should be considered
452ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// to never be a null pointer constant.
453ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNotNull
454ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  };
455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
456efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
457efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
458efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
459ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isNullPointerConstant(ASTContext &Ctx,
460ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                             NullPointerConstantValueDependence NPC) const;
461efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
46244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
464102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis  /// \brief Returns true if this expression is a bound member function.
46711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis  bool isBoundMemberFunction(ASTContext &Ctx) const;
46811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis
469369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief Result type of CanThrow().
470369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  enum CanThrowResult {
471369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CT_Cannot,
472369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CT_Dependent,
473369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CT_Can
474369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  };
475369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief Test if this expression, if evaluated, might throw, according to
476369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  ///        the rules of C++ [expr.unary.noexcept].
477369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  CanThrowResult CanThrow(ASTContext &C) const;
478369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
4794e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
4814e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
4824e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
4832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  Expr *IgnoreParens();
48456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
48556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
48627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
48756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4892fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
4902fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// ParenExpr or ImplicitCastExprs, returning their operand.
4912fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *IgnoreParenImpCasts();
4922fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
4934d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  const Expr *IgnoreParenImpCasts() const {
4944d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
4954d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  }
496f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall
497f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
498f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// CastExprs that represent lvalue casts, returning their operand.
499f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  Expr *IgnoreParenLValueCasts();
500f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall
501f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  const Expr *IgnoreParenLValueCasts() const {
502f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
503f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  }
5044d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek
505ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
506ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
507ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
508ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether this expression is a default function argument.
5116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
5126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Default arguments are implicitly generated in the abstract syntax tree
513c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// by semantic analysis for function calls, object constructions, etc. in
5146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
5156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// this routine also looks through any implicit casts to determine whether
5166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// the expression is a default argument.
5176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool isDefaultArgument() const;
518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
519558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// \brief Determine whether the result of this expression is a
520558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// temporary object of the given class type.
521558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
5222f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
5232b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const Expr *IgnoreParens() const {
5244e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
5254e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
52656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
52756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
52856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
529ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
530ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
531ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
533898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
534898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
535898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the
549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort".
550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier {
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The nested name specifier.
552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *NNS;
553c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source range covered by the nested name specifier.
555a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange Range;
556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g.,
559a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>".
560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList {
561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the left angle bracket ('<');
562a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation LAngleLoc;
563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
564a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the right angle bracket ('>');
565a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation RAngleLoc;
566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
567a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The number of template arguments in TemplateArgs.
568a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The actual template arguments (if any) are stored after the
569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// ExplicitTemplateArgumentList structure.
570a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned NumTemplateArgs;
571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
573833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc *getTemplateArgs() {
574833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
578833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
579833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
580a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
581d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
582d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void initializeFrom(const TemplateArgumentListInfo &List);
583bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeFrom(const TemplateArgumentListInfo &List,
584bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                      bool &Dependent, bool &ContainsUnexpandedParameterPack);
585d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyInto(TemplateArgumentListInfo &List) const;
5868dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static std::size_t sizeFor(unsigned NumTemplateArgs);
587d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
588a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
589c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
593a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  enum {
594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
595a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has a C++ nested-name-specifier.
596a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasQualifierFlag = 0x01,
597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
598a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has an explicit C++ template argument list.
599a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasExplicitTemplateArgumentListFlag = 0x02
600a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // DecoratedD - The declaration that we are referencing, plus two bits to
603a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // indicate whether (1) the declaration's name was explicitly qualified and
604c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // (2) the declaration's name was followed by an explicit template
605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // argument list.
606dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
6072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // Loc - The location of the declaration name itself.
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6109e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
6112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// DNLoc - Provides source/type location info for the
6122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// declaration name embedded in DecoratedD.
6132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc DNLoc;
6142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NameQualifier *getNameQualifier() {
6172cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
618a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
620a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<NameQualifier *> (this + 1);
621a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
623a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const NameQualifier *getNameQualifier() const {
625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
626a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
627096832c5ed5b9106fa177ebc148489760c3bc496John McCall
628a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
629dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall              ValueDecl *D, SourceLocation NameLoc,
630d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall              const TemplateArgumentListInfo *TemplateArgs,
631f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall              QualType T, ExprValueKind VK);
632663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
6332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
6342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara              ValueDecl *D, const DeclarationNameInfo &NameInfo,
6352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara              const TemplateArgumentListInfo *TemplateArgs,
636f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall              QualType T, ExprValueKind VK);
6372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
638663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
639663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  explicit DeclRefExpr(EmptyShell Empty)
640663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    : Expr(DeclRefExprClass, Empty) { }
641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// \brief Computes the type- and value-dependence flags for this
6430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// declaration reference expression.
6440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  void computeDependence();
6459e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
647f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  DeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK, SourceLocation l) :
648bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(DeclRefExprClass, t, VK, OK_Ordinary, false, false, false),
649f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    DecoratedD(d, 0), Loc(l) {
6500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
6510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static DeclRefExpr *Create(ASTContext &Context,
654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             NestedNameSpecifier *Qualifier,
655a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceRange QualifierRange,
656dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                             ValueDecl *D,
657a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceLocation NameLoc,
658f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                             QualType T, ExprValueKind VK,
6590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             const TemplateArgumentListInfo *TemplateArgs = 0);
660663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
6612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  static DeclRefExpr *Create(ASTContext &Context,
6622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             NestedNameSpecifier *Qualifier,
6632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             SourceRange QualifierRange,
6642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             ValueDecl *D,
6652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             const DeclarationNameInfo &NameInfo,
666f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                             QualType T, ExprValueKind VK,
6672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             const TemplateArgumentListInfo *TemplateArgs = 0);
6682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
669663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
670663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  static DeclRefExpr *CreateEmpty(ASTContext &Context,
671663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis                                  bool HasQualifier, unsigned NumTemplateArgs);
672c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
673dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
674dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
675dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
676904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
6772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo getNameInfo() const {
6782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
6792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
6802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6819e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
6820b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
683a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  virtual SourceRange getSourceRange() const;
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
685a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
686a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// C++ nested-name-specifier, e.g., \c N::foo.
687a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
688c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief If the name was qualified, retrieves the source range of
690a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// the nested-name-specifier that precedes the name. Otherwise,
691a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returns an empty source range.
692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange getQualifierRange() const {
693a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceRange();
695c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
696a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->Range;
697a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
698c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief If the name was qualified, retrieves the nested-name-specifier
700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that precedes the name. Otherwise, returns NULL.
701a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *getQualifier() const {
702a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
703a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
704c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
705a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->NNS;
706a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
707c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
708096832c5ed5b9106fa177ebc148489760c3bc496John McCall  bool hasExplicitTemplateArgs() const {
709096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag);
710096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
711096832c5ed5b9106fa177ebc148489760c3bc496John McCall
712096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that followed the
713096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// member template name.
714096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
715096832c5ed5b9106fa177ebc148489760c3bc496John McCall    assert(hasExplicitTemplateArgs());
716096832c5ed5b9106fa177ebc148489760c3bc496John McCall
717096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
718096832c5ed5b9106fa177ebc148489760c3bc496John McCall      return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
719096832c5ed5b9106fa177ebc148489760c3bc496John McCall
720096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(
721096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                                      getNameQualifier() + 1);
722096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
723096832c5ed5b9106fa177ebc148489760c3bc496John McCall
724096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that followed the
725096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// member template name.
726096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
727096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
728a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
729d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
730096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
731096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
732096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
733096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const {
734096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
735096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
736096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
737096832c5ed5b9106fa177ebc148489760c3bc496John McCall
738d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
739d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
740d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
741096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (hasExplicitTemplateArgs())
742096832c5ed5b9106fa177ebc148489760c3bc496John McCall      getExplicitTemplateArgs().copyInto(List);
743d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
744c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
745a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the left angle bracket following the
746a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member name ('<'), if any.
747a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getLAngleLoc() const {
748096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
749a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
750c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
751096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().LAngleLoc;
752a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
753c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
754a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments provided as part of this
755a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
756833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
757096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
758a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
759c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
760096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
761a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
762c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
763a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned getNumTemplateArgs() const {
766096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
767a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
769096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
770a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
771c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
772a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the right angle bracket following the
773a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template arguments ('>').
774a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getRAngleLoc() const {
775096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
776a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
777c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
778096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().RAngleLoc;
779a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
780c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
78299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    return T->getStmtClass() == DeclRefExprClass;
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
78777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
78877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
789663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
79060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
7913397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
794d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
795d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
796227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
797227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
798227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
799227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
800848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunction,
801848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
802848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// 'virtual' keyword is omitted for virtual member functions.
803848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunctionNoVirtual
804227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
806227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
807227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
808227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
809227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
811f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
812bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           type->isDependentType(), type->isDependentType(),
813bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
814f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Loc(l), Type(IT) {}
8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
81817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
81917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
820227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
82117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
82217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
82317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
82417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
82517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
826848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
8273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
828227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
829227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
832227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
833d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
83677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
83777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
838227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
839227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
8409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
8419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory.
8429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///
8439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap
8449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
8459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
8469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses
8479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation.
8489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage {
8499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  unsigned BitWidth;
8509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  union {
8519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
8529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
8539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  };
8549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
8569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APNumericStorage(const APNumericStorage&); // do not implement
8589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APNumericStorage& operator=(const APNumericStorage&); // do not implement
8599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected:
8619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APNumericStorage() : BitWidth(0), VAL(0) { }
8629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APInt getIntValue() const {
8649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
8659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (NumWords > 1)
8669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return llvm::APInt(BitWidth, NumWords, pVal);
8679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    else
8689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return llvm::APInt(BitWidth, VAL);
8699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
8709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setIntValue(ASTContext &C, const llvm::APInt &Val);
8719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
8729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage {
8749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic:
8759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APInt getValue() const { return getIntValue(); }
8769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
8779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
8789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage {
8809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic:
8819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); }
8829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APFloat &Val) {
8839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    setIntValue(C, Val.bitcastToAPInt());
8849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
8859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
8869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
8889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APIntStorage Num;
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
8909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Construct an empty integer literal.
8929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  explicit IntegerLiteral(EmptyShell Empty)
8939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    : Expr(IntegerLiteralClass, Empty) { }
8949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
8989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  IntegerLiteral(ASTContext &C, const llvm::APInt &V,
8999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                 QualType type, SourceLocation l)
900bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
901bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false),
902f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Loc(l) {
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
9049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    setValue(C, V);
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
906a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
9079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
9089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  // or UnsignedLongLongTy
9099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
9109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                QualType type, SourceLocation l);
9119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
9120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
9139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APInt getValue() const { return Num.getValue(); }
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
916313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
917313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
918313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
9199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); }
9200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
9210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
92877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
92977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
935c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
938c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
939bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
940bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false),
941f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Value(value), Loc(l), IsWide(iswide) {
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
9440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
9450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
9460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
947018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
948c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
9550b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
9560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
9570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
96277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
96377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
96577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
9699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APFloatStorage Num;
970720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
9729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
974720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
975bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
976bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false),
9779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      IsExact(isexact), Loc(L) {
9789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    setValue(C, V);
9799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
98117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit FloatingLiteral(EmptyShell Empty)
9839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    : Expr(FloatingLiteralClass, Empty), IsExact(false) { }
98417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
9859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic:
9869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
9879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                 bool isexact, QualType Type, SourceLocation L);
9889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
9899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APFloat getValue() const { return Num.getValue(); }
9919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APFloat &Val) {
9929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    Num.setValue(C, Val);
9939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
99417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
995720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
99617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
997c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
998da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
999da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
1000da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
1001da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
100417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
100517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
101477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
101577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
10195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
10205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
10215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
10225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
10235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
10245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
10255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
10265d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
1027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false),
1029f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Val(val) {}
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1031cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
1033cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
1034cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
10355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
10365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1037cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1038cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
10395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
10425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
10435d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
10465d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
10475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
10485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
10495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
1050e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
1051e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
1052e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
1053a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
1054c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
1055c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
1056690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
1057690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
10588bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
1059690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
1060c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
1061c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
1062c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
1063c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
1064c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
1065c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
1070726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
1071726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
10722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
1073f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  StringLiteral(QualType Ty) :
1074bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false) {}
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
10782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
10792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
10802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
1081a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
10822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
10832085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static StringLiteral *Create(ASTContext &C, const char *StrData,
10852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
10862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
10872085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
10882085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
1089a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
1090673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
1091673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
1092673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1093b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  llvm::StringRef getString() const {
1094b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return llvm::StringRef(StrData, ByteLength);
1095b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
10962f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
1098673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1099673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
1100b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void setString(ASTContext &C, llvm::StringRef Str);
1101673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
1103673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
1104673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
11058d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
1106b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    llvm::StringRef Str = getString();
1107b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
1108b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
110933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
111033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
111133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
1112726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
1113726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
1114726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1116726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1117726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
1118726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
1119726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1121673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
1122673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
1123673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
112408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner
112508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// getLocationOfByte - Return a source location that points to the specified
112608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// byte of this string literal.
112708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  ///
112808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// Strings are amazingly complex.  They can be formed from multiple tokens
112908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// and can have escape sequences in them in addition to the usual trigraph
113008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// and escaped newline business.  This routine handles this complexity.
113108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  ///
113208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
113308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner                                   const LangOptions &Features,
113408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner                                   const TargetInfo &Target) const;
1135673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1136b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
1137b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
1138b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
114977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
115077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
11575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
1161f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           val->getValueKind(), val->getObjectKind(),
1162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->isTypeDependent(), val->isValueDependent(),
1163bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->containsUnexpandedParameterPack()),
1164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1166c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
1168c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
1169c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
11705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
11715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1172c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1173c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
1174866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1176313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
1177313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
1178c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
1179313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
1180313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
1181313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
1182c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
1183313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
119077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
119177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
11960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
1198dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1199dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
1200dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1201dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
1202dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
1203dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
1204dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef UnaryOperatorKind Opcode;
12085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
12100799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  unsigned Opc : 5;
12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
12120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Stmt *Val;
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1215f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  UnaryOperator(Expr *input, Opcode opc, QualType type,
1216f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
1217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryOperatorClass, type, VK, OK,
1218de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman           input->isTypeDependent() || type->isDependentType(),
1219bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           input->isValueDependent(),
1220bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           input->containsUnexpandedParameterPack()),
12210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall      Opc(opc), Loc(l), Val(input) {}
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
12252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
12260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12270799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
12280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
12290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
12310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
12320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
12350b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
12360b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
12382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
12392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op == UO_PostInc || Op == UO_PostDec;
12402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1242cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan  /// isPrefix - Return true if this is a prefix operation, like --x.
12432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
12442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op == UO_PreInc || Op == UO_PreDec;
12452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
12465a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
12470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isPrefix() const { return isPrefix(getOpcode()); }
12480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isPostfix() const { return isPostfix(getOpcode()); }
12492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isIncrementOp() const {
1250993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer    return Opc == UO_PreInc || Opc == UO_PostInc;
12512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
12522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isIncrementDecrementOp() const {
1253993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer    return Opc <= UO_PreDec;
12542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
12552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isArithmeticOp(Opcode Op) {
12562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op >= UO_Plus && Op <= UO_LNot;
12572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
12580799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1264bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
1265bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
1266bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1267bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1268bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1269bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
1270bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1271bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
128577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
128677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
128777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given:
12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code
12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S {
12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   float f;
1295c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   double d;
12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T {
12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   int i;
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   struct S s[10];
13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode
1302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
13038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr {
13058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
13068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  class OffsetOfNode {
13088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
13098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The kind of offsetof node we have.
13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum Kind {
1311cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An index into an array.
13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Array = 0x00,
1313cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field.
13148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Field = 0x01,
1315cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field in a dependent type, known only by its name.
1316cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Identifier = 0x02,
1317cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An implicit indirection through a C++ base class, when the
1318cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// field found is in a base class.
1319cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Base = 0x03
13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    };
13218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  private:
13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum { MaskBits = 2, Mask = 0x03 };
1324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The source range that covers this part of the designator.
13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange Range;
1327c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The data describing the designator, which comes in three
13298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// different forms, depending on the lower two bits.
1330c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - An unsigned index into the array of Expr*'s stored after this node
13318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     in memory, for [constant-expression] designators.
13328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - A FieldDecl*, for references to a known field.
13338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - An IdentifierInfo*, for references to a field with a given name
13348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     when the class type is dependent.
1335c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1336cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    ///     base class.
13378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    uintptr_t Data;
1338c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
13408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an array element.
1341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
13428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation RBracketLoc)
13438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1344c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to a field.
1346c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
13478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
13498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an identifier.
13528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
13538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1356cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1357cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1358cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1359cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Determine what kind of offsetof node this is.
1362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Kind getKind() const {
13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return static_cast<Kind>(Data & Mask);
13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1365c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For an array element node, returns the index into the array
13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// of expressions.
13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    unsigned getArrayExprIndex() const {
13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Array);
13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return Data >> 2;
13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field offsetof node, returns the field.
13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    FieldDecl *getField() const {
13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Field);
1376cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field or identifier offsetof node, returns the name of
13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the field.
13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    IdentifierInfo *getFieldName() const;
1382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1383cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief For a base class node, returns the base specifier.
1384cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    CXXBaseSpecifier *getBase() const {
1385cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      assert(getKind() == Base);
1386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1387cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    }
1388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Retrieve the source range that covers this offsetof node.
13908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///
13918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// For an array element node, the source range contains the locations of
13928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
1393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// contains the location of the period (if there is one) and the
13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// identifier.
13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange getRange() const { return Range; }
13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
13978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
1399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation OperatorLoc, RParenLoc;
14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Base type;
14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *TSInfo;
14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-components (i.e. instances of OffsetOfNode).
14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumComps;
14058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
14068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumExprs;
1407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1408c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  OffsetOfExpr(ASTContext &C, QualType type,
14098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt               OffsetOfNode* compsPtr, unsigned numComps,
14118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               Expr** exprsPtr, unsigned numExprs,
14128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation RParenLoc);
14138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
14158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(OffsetOfExprClass, EmptyShell()),
1416c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
14178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1420c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1422c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              OffsetOfNode* compsPtr, unsigned numComps,
14238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
14248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              SourceLocation RParenLoc);
14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1426c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *CreateEmpty(ASTContext &C,
14278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   unsigned NumComps, unsigned NumExprs);
14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getOperatorLoc - Return the location of the operator.
14308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
14318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
14328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Return the location of the right parentheses.
14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
14358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1436c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
14388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TSInfo;
14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setTypeSourceInfo(TypeSourceInfo *tsi) {
14418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TSInfo = tsi;
14428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1443c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const OffsetOfNode &getComponent(unsigned Idx) {
14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
14468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setComponent(unsigned Idx, OffsetOfNode ON) {
14508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
14518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
14528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1453c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumComponents() const {
14558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumComps;
14568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr* getIndexExpr(unsigned Idx) {
14598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumExprs && "Subscript out of range");
14608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<Expr **>(
14618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
14628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setIndexExpr(unsigned Idx, Expr* E) {
14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
14668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<Expr **>(
14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
14688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumExpressions() const {
14718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumExprs;
14728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual SourceRange getSourceRange() const {
14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(OperatorLoc, RParenLoc);
14768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
14808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
14838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
14858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_begin();
14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_end();
14878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
14900518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
14910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
14920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
14930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
1494d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
1495a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *Ty;
1496d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
1497d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
149942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1501a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
15020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
15030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
1504f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary,
1505ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
15062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
1507bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           TInfo->getType()->isDependentType(),
1508bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           TInfo->getType()->containsUnexpandedParameterPack()),
1509ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1510a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1511ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
1512ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1514ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
1515ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
1516f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Expr(SizeOfAlignOfExprClass, resultType, VK_RValue, OK_Ordinary,
1517ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1518ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
1519bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           E->isTypeDependent(),
1520bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           E->containsUnexpandedParameterPack()),
1521ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1522ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
1523d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
15240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
15250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
15260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
15270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
15280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
15300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
15310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
15330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
15345ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getArgumentTypeInfo()->getType();
15355ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  }
1536a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *getArgumentTypeInfo() const {
15370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
15385ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return Argument.Ty;
15390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1540caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
15410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1542d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
15430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1544caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
1545caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1546caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
15470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1549a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  void setArgument(TypeSourceInfo *TInfo) {
1550a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    isType = true;
15520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
15530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
15550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
15560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
15570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
15580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
15590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
156076e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
15610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
15620b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
15640b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1565866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1566866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
1567866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
1568866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SizeOfAlignOfExprClass;
15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
157577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
157677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
157777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
15855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
158677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1591f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     ExprValueKind VK, ExprObjectKind OK,
159273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
1593f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  : Expr(ArraySubscriptExprClass, t, VK, OK,
15942850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
1595bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         lhs->isValueDependent() || rhs->isValueDependent(),
1596bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         (lhs->containsUnexpandedParameterPack() ||
1597bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          rhs->containsUnexpandedParameterPack())),
15982850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
159973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
160073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
160173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
1604cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
1605cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
1606cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
16072324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
16082324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
16092324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
16102324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
16112324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
161233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
161333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
161433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
161533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
16165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
16175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1618cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1619cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
16205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
16215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1622cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
16255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
162677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
16295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
16302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
16335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
16342324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
163677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
16375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
164177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1644026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1645cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1646cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
16475cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
165577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
165677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1660b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1662b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
1664b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1665b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
166777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
16685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1672b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
1673b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
1674668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1675f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           QualType t, ExprValueKind VK, SourceLocation rparenloc);
167642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
16775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
1679f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           ExprValueKind VK, SourceLocation rparenloc);
16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
1682ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
16831f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
16845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
16855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
168618b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
1687a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1688d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  Decl *getCalleeDecl();
1689d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  const Decl *getCalleeDecl() const {
1690d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return const_cast<CallExpr*>(this)->getCalleeDecl();
1691d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
1692d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
1693a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1694a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
1695bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  const FunctionDecl *getDirectCallee() const {
1696bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
1697bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
1698a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
17005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1703aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the call arguments.
1704aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getArgs() { return reinterpret_cast<Expr **>(SubExprs + ARGS_START); }
1705aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
17095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
17135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
17145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1716934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
1717934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
1718934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
1719934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
1720934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1722d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
1723d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
1724d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
17258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
17285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1730d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1731d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
17325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
17335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
17365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1739cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1740cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
17414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  unsigned isBuiltinCall(const ASTContext &Context) const;
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
17441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
17456dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
17466dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1748d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
17491f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1750866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
175277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
17564bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCallExprConstant &&
17574bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCallExprConstant;
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
176088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
176177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
176277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
176377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1766ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
17696bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// Extra data stored in some member expressions.
17706bb8017bb9e828d118e15e59d71c66bba323c364John McCall  struct MemberNameQualifier : public NameQualifier {
1771161755a09898c95d21bfff33707da9ca41cd53c5John McCall    DeclAccessPair FoundDecl;
17726bb8017bb9e828d118e15e59d71c66bba323c364John McCall  };
17736bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1774ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1775ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
17765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1778ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1779ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
1780f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *MemberDecl;
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1782ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
17835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// MemberDNLoc - Provides source/type location info for the
17862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// declaration name embedded in MemberDecl.
17872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc MemberDNLoc;
17882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
1789ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
179083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
17936bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
17946bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// declaration.  When true, a MemberNameQualifier
1795c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
17966bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool HasQualifierOrFoundDecl : 1;
17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1798c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief True if this member expression specified a template argument list
1799c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1800c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure (and its TemplateArguments) are allocated immediately after
1801c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier, after
18026bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// the MemberNameQualifier structure.
1803c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  bool HasExplicitTemplateArgumentList : 1;
18041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
180583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
18066bb8017bb9e828d118e15e59d71c66bba323c364John McCall  MemberNameQualifier *getMemberQualifier() {
18076bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(HasQualifierOrFoundDecl);
18086bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return reinterpret_cast<MemberNameQualifier *> (this + 1);
180983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
181083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
181183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
18126bb8017bb9e828d118e15e59d71c66bba323c364John McCall  const MemberNameQualifier *getMemberQualifier() const {
1813c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1814c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
18151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1817f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1818f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             const DeclarationNameInfo &NameInfo, QualType ty,
1819f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             ExprValueKind VK, ExprObjectKind OK)
1820f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(MemberExprClass, ty, VK, OK,
1821bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->isTypeDependent(), base->isValueDependent(),
1822bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
18232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()),
18242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow),
18252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {
18262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(memberdecl->getDeclName() == NameInfo.getName());
18272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
18282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // NOTE: this constructor should be used only when it is known that
18302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // the member name can not provide additional syntactic info
18312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // (i.e., source locations for C++ operator names or type source info
18322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // for constructors, destructors and conversion oeprators).
18332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1834f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             SourceLocation l, QualType ty,
1835f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             ExprValueKind VK, ExprObjectKind OK)
1836f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(MemberExprClass, ty, VK, OK,
1837bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->isTypeDependent(), base->isValueDependent(),
1838bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
18392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(),
18402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      IsArrow(isarrow),
18416bb8017bb9e828d118e15e59d71c66bba323c364John McCall      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1842510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
184483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                            NestedNameSpecifier *qual, SourceRange qualrange,
1845161755a09898c95d21bfff33707da9ca41cd53c5John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
18462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            DeclarationNameInfo MemberNameInfo,
1847d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                            const TemplateArgumentListInfo *targs,
1848f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            QualType ty, ExprValueKind VK, ExprObjectKind OK);
18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
185088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
18515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
185257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
185357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
185457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
185557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
185657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
1857f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *getMemberDecl() const { return MemberDecl; }
1858f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
18591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
18606bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// \brief Retrieves the declaration found by lookup.
1861161755a09898c95d21bfff33707da9ca41cd53c5John McCall  DeclAccessPair getFoundDecl() const {
18626bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1863161755a09898c95d21bfff33707da9ca41cd53c5John McCall      return DeclAccessPair::make(getMemberDecl(),
1864161755a09898c95d21bfff33707da9ca41cd53c5John McCall                                  getMemberDecl()->getAccess());
18656bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return getMemberQualifier()->FoundDecl;
18666bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
18676bb8017bb9e828d118e15e59d71c66bba323c364John McCall
18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
18690979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
18700979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
18716bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool hasQualifier() const { return getQualifier() != 0; }
18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
187383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
187483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
187583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// returns an empty source range.
18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getQualifierRange() const {
18776bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
187883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return SourceRange();
18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->Range;
188183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
188483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
188583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
18876bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
188883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
189083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->NNS;
189183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
1892c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1893c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
1894c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
1895096832c5ed5b9106fa177ebc148489760c3bc496John McCall  bool hasExplicitTemplateArgs() const {
18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return HasExplicitTemplateArgumentList;
1897c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1899d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1900d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1901d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1902096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (hasExplicitTemplateArgs())
1903096832c5ed5b9106fa177ebc148489760c3bc496John McCall      getExplicitTemplateArgs().copyInto(List);
1904096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1905096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1906096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that
1907096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// follow the member template name.  This must only be called on an
1908096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// expression with explicit template arguments.
1909096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1910096832c5ed5b9106fa177ebc148489760c3bc496John McCall    assert(HasExplicitTemplateArgumentList);
1911096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!HasQualifierOrFoundDecl)
1912096832c5ed5b9106fa177ebc148489760c3bc496John McCall      return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1913096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1914096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(
1915096832c5ed5b9106fa177ebc148489760c3bc496John McCall                                                      getMemberQualifier() + 1);
1916096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1917096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1918096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that
1919096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// followed the member template name.  This must only be called on
1920096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// an expression with explicit template arguments.
1921096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1922096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
1923096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1924096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1925096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1926096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1927096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1928096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const {
1929096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1930096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1931d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1932c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
1934c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member name ('<'), if any.
19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1936c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1937c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1939096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().LAngleLoc;
1940c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1942c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1943c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
1944833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1945c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1948096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1949c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1951c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1952c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
1954c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1957096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1958c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
1961c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template arguments ('>').
19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
1963c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1964c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1966096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().RAngleLoc;
1967c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the member declaration name info.
19702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo getMemberNameInfo() const {
19712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo(MemberDecl->getDeclName(),
19722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                               MemberLoc, MemberDNLoc);
19732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
19742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
19761f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
19771f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1978ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1979ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1980026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
19811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
198472527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
198572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
19862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceLocation EndLoc = (HasExplicitTemplateArgumentList)
19872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      ? getRAngleLoc() : getMemberNameInfo().getEndLoc();
19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
198972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
199072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
1991c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceRange(MemberLoc, EndLoc);
1992c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return SourceRange(BaseLoc, EndLoc);
19935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
199883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20021237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
20031237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
20041237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
20054045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
20064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTReader;
20074045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
20085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
2011aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
2012aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
20130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
20140fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
20150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
20160fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
20171d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
20181d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// The type as written.  This can be an incomplete array type, in
20191d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// which case the actual expression type will be different.
202042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *TInfo;
20215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
2022e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
2023aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
202442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2025f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2026f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           tinfo->getType()->isDependentType(),
2028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           init->isValueDependent(),
2029bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           init->containsUnexpandedParameterPack()),
203042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2032ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
2033ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
2034ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
2035ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
20365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
20375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
2038ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
2039e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
2040e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
2041ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
2042ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
20430fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
2044ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2045ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
204642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
204742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
204842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall
204973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
20500fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
20510fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
20520fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
20530fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
205473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
20550fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
205673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
2057aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
2060aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
2061aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20631237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
20641237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
20651237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2066aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
2067aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
206849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
206949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
207049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
207149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
20720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
2073cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
20745baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef clang::CastKind CastKind;
20751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2076cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
20770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
2078409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2079daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  void CheckCastConsistency() const {
2080409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG
2081409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    switch (getCastKind()) {
20825cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    case CK_DerivedToBase:
2083cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_UncheckedDerivedToBase:
2084cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_DerivedToBaseMemberPointer:
2085409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerived:
2086409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerivedMemberPointer:
2087f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      assert(!path_empty() && "Cast kind should have a base path!");
2088f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      break;
2089409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2090409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    // These should not have an inheritance path.
2091409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BitCast:
2092409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Dynamic:
2093409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToUnion:
2094409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ArrayToPointerDecay:
2095409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FunctionToPointerDecay:
2096409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NullToMemberPointer:
2097404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall    case CK_NullToPointer:
2098409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ConstructorConversion:
2099409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToPointer:
2100409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_PointerToIntegral:
2101409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToVoid:
2102409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_VectorSplat:
2103409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralCast:
2104409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToFloating:
2105409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingToIntegral:
2106409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingCast:
2107409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToObjCPointerCast:
2108409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToBlockPointerCast:
2109569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    case CK_ObjCObjectLValueCast:
21102bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    case CK_FloatingRealToComplex:
2111f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall    case CK_FloatingComplexToReal:
21122bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    case CK_FloatingComplexCast:
2113f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall    case CK_FloatingComplexToIntegralComplex:
21142bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    case CK_IntegralRealToComplex:
2115f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall    case CK_IntegralComplexToReal:
21162bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    case CK_IntegralComplexCast:
2117f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall    case CK_IntegralComplexToFloatingComplex:
2118daa8e4e888758d55a7a759dd4a91b83921cef222John McCall      assert(!getType()->isBooleanType() && "unheralded conversion to bool");
2119daa8e4e888758d55a7a759dd4a91b83921cef222John McCall      // fallthrough to check for null base path
2120daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
2121daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_Dependent:
21220ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall    case CK_LValueToRValue:
2123f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    case CK_GetObjCProperty:
2124daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_NoOp:
2125daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_PointerToBoolean:
2126daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_IntegralToBoolean:
2127daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_FloatingToBoolean:
2128daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_MemberPointerToBoolean:
2129daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_FloatingComplexToBoolean:
2130daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    case CK_IntegralComplexToBoolean:
21315082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall    case CK_LValueBitCast:            // -> bool&
21325082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall    case CK_UserDefinedConversion:    // operator bool()
2133f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      assert(path_empty() && "Cast kind should not have a base path!");
2134409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson      break;
2135409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
2136409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif
2137409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2138409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2139f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const CXXBaseSpecifier * const *path_buffer() const {
2140f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return const_cast<CastExpr*>(this)->path_buffer();
2141f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
2142f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXBaseSpecifier **path_buffer();
2143f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
21440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
2145f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
2146f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           const CastKind kind, Expr *op, unsigned BasePathSize) :
2147f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(SC, ty, VK, OK_Ordinary,
2148898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
2149898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
2150898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
2151898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
2152898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
2153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent()),
2154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         (ty->containsUnexpandedParameterPack() ||
2155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          op->containsUnexpandedParameterPack())),
21568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Op(op) {
2157daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    assert(kind != CK_Invalid && "creating cast with invalid cast kind");
21588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBits.Kind = kind;
21598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBits.BasePathSize = BasePathSize;
2160daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    CheckCastConsistency();
2161f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2163087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
2164f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
21658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Expr(SC, Empty) {
21668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBits.BasePathSize = BasePathSize;
21678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
21681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
21708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
21718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2172f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
2173f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
21740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
21750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2176087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
2177087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
21786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
21796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// code, looking through any implicit casts or other intermediate nodes
21806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// introduced by semantic analysis.
21816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *getSubExprAsWritten();
21826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *getSubExprAsWritten() const {
21836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
21846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
218541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
2186f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  typedef CXXBaseSpecifier **path_iterator;
2187f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  typedef const CXXBaseSpecifier * const *path_const_iterator;
21888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool path_empty() const { return CastExprBits.BasePathSize == 0; }
21898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned path_size() const { return CastExprBits.BasePathSize; }
2190f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_iterator path_begin() { return path_buffer(); }
2191f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_iterator path_end() { return path_buffer() + path_size(); }
2192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_const_iterator path_begin() const { return path_buffer(); }
2193f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void setCastPath(const CXXCastPath &Path);
219641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21984bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCastExprConstant &&
21994bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCastExprConstant;
22000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
22010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
22040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
22050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
22060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
22070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
220849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
220949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
221049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
221149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
221249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
2213bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
2214bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
2215906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example:
2216bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
2217bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
2218bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
2219bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
2220906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref();
22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
2222906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///   Base& b = d; // initializer is an ImplicitCastExpr
2223906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///                // to an lvalue of type Base
2224906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///   Base&& r = ref(); // initializer is an ImplicitCastExpr
2225906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///                     // to an xvalue of type Base
2226bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
2227bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
22280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
2229906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate:
2230f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
22315baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                   unsigned BasePathLength, ExprValueKind VK)
2232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
22335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
223490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
2235087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
2236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
2240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  enum OnStack_t { OnStack };
2241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
22425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                   ExprValueKind VK)
2243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
22445baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
2245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                  CastKind Kind, Expr *Operand,
2248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                  const CXXCastPath *BasePath,
22495baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                  ExprValueKind Cat);
2250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2252087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
22530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
22540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
22550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
225690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
22571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
225949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
226049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
226149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
226249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
226349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
226549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
226649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
226749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
226849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
226949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
227049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
22715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
227249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
227349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
227449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
227549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
227649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
2277906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however,
2278906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression.
22790835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
22809d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// TInfo - Source type info for the (written) type
22819d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// this expression is casting to.
22829d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *TInfo;
228349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
228449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
2285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
2286f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
2287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   TypeSourceInfo *writtenTy)
2288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
228949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
2290db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
2291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
2292f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CastExpr(SC, Shell, PathSize) { }
2293db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
229449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
22959d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// getTypeInfoAsWritten - Returns the type source info for the type
22969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// that this expression is casting to.
22979d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
22989d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
22999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
230049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
230149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
23029d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  QualType getTypeAsWritten() const { return TInfo->getType(); }
230349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
23041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
23054bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt     return T->getStmtClass() >= firstExplicitCastExprConstant &&
23064bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt            T->getStmtClass() <= lastExplicitCastExprConstant;
230749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
230849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
230949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
231049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
23116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
231249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
231349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
23146eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
2315b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2316b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
2317f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
2319f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                 unsigned PathSize, TypeSourceInfo *writtenTy,
232041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 SourceLocation l, SourceLocation r)
2321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
232241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy), LPLoc(l), RPLoc(r) {}
232349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
2324db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
2325f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2326f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2327f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2328f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
2329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CStyleCastExpr *Create(ASTContext &Context, QualType T,
2330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                ExprValueKind VK, CastKind K,
2331f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                Expr *Op, const CXXCastPath *BasePath,
2332f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                TypeSourceInfo *WrittenTy, SourceLocation L,
2333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                SourceLocation R);
2334f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2335f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2336db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2337b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
2338db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2339db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2340b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
2341db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2342db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
2344b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23496eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
23505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
23533fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
23543fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
23553fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
23563fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
23573fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
23583fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
23593fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
23603fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
23613fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
23623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
23633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
23643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
23653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
23663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
23673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
23683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
23693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
23715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef BinaryOperatorKind Opcode;
23735baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
237417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
23750799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  unsigned Opc : 6;
23760799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  SourceLocation OpLoc;
23770799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
237817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
23795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
23801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
23811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
238217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2383f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                 ExprValueKind VK, ExprObjectKind OK,
238417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
2385f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(BinaryOperatorClass, ResTy, VK, OK,
2386898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
2387bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
2388bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhs->containsUnexpandedParameterPack() ||
2389bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
2390898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
23911237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
23921237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
23931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
23955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2397db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
23981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
23992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
2400db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
240117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
2402db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2403db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
24040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
2405db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
2406db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
24075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2408db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
24095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2410db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2411db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
24125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
24135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
24145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
24185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
24195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24200799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
2421a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek
2422063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
2423063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
2424063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2425063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2426063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
2427063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
2428063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2429063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
2431200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
24322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
24332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
24340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
24352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
24360799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isShiftOp() const { return isShiftOp(getOpcode()); }
2437aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
24382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
24390799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
2440f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
24412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
24420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
2443f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
24442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
24450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
24480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
2449aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
24502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
24510799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
2452f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
24530e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isAssignmentOp(Opcode Opc) {
24540e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return Opc >= BO_Assign && Opc <= BO_OrAssign;
24550e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
24560e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
24570e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
24580e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isCompoundAssignmentOp(Opcode Opc) {
24592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Opc > BO_Assign && Opc <= BO_OrAssign;
24602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
24610e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isCompoundAssignmentOp() const {
24620e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return isCompoundAssignmentOp(getOpcode());
24630e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
24640e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
24650e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isShiftAssignOp(Opcode Opc) {
24662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
24672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
24680e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isShiftAssignOp() const {
24690e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return isShiftAssignOp(getOpcode());
24700e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
24711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
24734bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return S->getStmtClass() >= firstBinaryOperatorConstant &&
24744bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           S->getStmtClass() <= lastBinaryOperatorConstant;
24755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
24771237c673c07f9d827129ba02720108816abde562Ted Kremenek
24781237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24791237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24801237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
24811237c673c07f9d827129ba02720108816abde562Ted Kremenek
24825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
248317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2484f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                 ExprValueKind VK, ExprObjectKind OK,
24852333f7727f97018d6742e1e0938133bcfad967abEli Friedman                 SourceLocation opLoc, bool dead)
2486f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
24872333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
2488bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
2489bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhs->containsUnexpandedParameterPack() ||
2490bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
24912333f7727f97018d6742e1e0938133bcfad967abEli Friedman      Opc(opc), OpLoc(opLoc) {
24921237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
24931237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
24945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2495ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
24972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(SC, Empty), Opc(BO_MulAssign) { }
24985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
25025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
25035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
25045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
25055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
25065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
2507ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
2508ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
25095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2510f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
2511f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         ExprValueKind VK, ExprObjectKind OK,
2512f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         QualType CompLHSType, QualType CompResultType,
251317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
2514f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true),
2515ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
2516ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
25185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
25195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2521ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
2522ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
2523ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2524ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2525ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
2526ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
2527ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2528ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
2529ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2530ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2531ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
2532ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
2533ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
25345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
25361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
25375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
25415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
25425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
25441237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
25455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2546f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  Stmt* Save;
254747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
25485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
254947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
2550f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      SourceLocation CLoc, Expr *rhs, Expr *save,
25510943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                      QualType t, ExprValueKind VK, ExprObjectKind OK)
25520943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall    : Expr(ConditionalOperatorClass, t, VK, OK,
2553898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
2554898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
2555898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
2556898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
25571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (cond->isValueDependent() ||
2558898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
2559bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            (rhs && rhs->isValueDependent())),
2560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
2561bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            (lhs && lhs->containsUnexpandedParameterPack()) ||
2562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            (rhs && rhs->containsUnexpandedParameterPack()))),
256347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      QuestionLoc(QLoc),
256447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      ColonLoc(CLoc) {
25651237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
25661237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
25671237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
2568f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian    Save = save;
25691237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
25705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2571ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
2572ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
2573ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
2574ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2575395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
2576395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
25775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2578ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
2579395a2abf0028968d85958610e393e067885dc14fTed Kremenek
2580395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2581f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  //  expression if the condition evaluates to true.
2582395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
2583af9b96828f9126d993c3e155b8453be62013b735Fariborz Jahanian    return cast<Expr>(SubExprs[LHS]);
2584395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2586ae2777cfe7d21f73e5a4155082fe20197cec62bdNick Lewycky  // getFalseExpr - Return the subexpression representing the value of the ?:
2587395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
25885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
2589f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
2590f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  // getSaveExpr - In most cases this value will be null. Except a GCC extension
2591f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  // allows the left subexpression to be omitted, and instead of that condition
2592f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  // be returned. e.g: x ?: y is shorthand for x ? x : y, except that the
2593f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  // expression "x" is only evaluated once. Under this senario, this function
2594f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  // returns the original, non-converted condition expression for the ?:operator
2595f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  Expr *getSaveExpr() const { return Save? cast<Expr>(Save) : (Expr*)0; }
2596f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
2597f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  Expr *getLHS() const { return Save ? 0 : cast<Expr>(SubExprs[LHS]); }
2598ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2599ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
26005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2601ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
26025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2603f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  Expr *getSAVE() const { return Save? cast<Expr>(Save) : (Expr*)0; }
2604f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  void setSAVE(Expr *E) { Save = E; }
2605f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
260647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
260747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
260847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
260947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
261047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
261147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
26125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
26135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
26145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
26175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26201237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
26211237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
26221237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
26235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26256481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
26266481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
26275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
26285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
26295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26306481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
26316481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
2632bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false),
26332333f7727f97018d6742e1e0938133bcfad967abEli Friedman      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
26377d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
26387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
26397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
26407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
26417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
26427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
26437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
26445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
26455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
26465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
26497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
26507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
26515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26546481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26561237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
26571237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
26581237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
26595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2660ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2661ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2662ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2663ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
2664f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall///
2665f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a
2666f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied.
2667ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
26685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
2669ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
2670ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
26712333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Does type-dependence need to be computed differently?
2672d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
2673d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
2674f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
2675bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         T->isDependentType(), false, false),
26762333f7727f97018d6742e1e0938133bcfad967abEli Friedman    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26786a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
26796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
26806a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
26815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
26825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
26836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
26846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
2685ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
2686ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
2687ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2689026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
26906a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2691026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
26926a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
26931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2694ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
2696ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
2697ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26991237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
27001237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
27011237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2702ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
2703ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2704d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
2705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
2706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
2707d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
2708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
2709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
2710d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
2711d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
2712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
2713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2714d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
2715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
2716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
2717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
27185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
2719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
2720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
2722a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
27231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
2724bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                    SourceLocation RP);
272594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
272694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
272894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
272994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
273094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
273194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
273394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
273494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
273594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2736d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
2737d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
2738d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2739d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
2741d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2742d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
27431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2744d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2745d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
2746d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
2747d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2749aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the array of expressions.
2750aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
2751aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2752d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
2753d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
2754d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
27555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2756d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2757d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
2758d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
27595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2760d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
27611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2762888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
276394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2764dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2765dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
27669a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2767d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
27681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2769d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
2770d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
2771d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
2772d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
2773d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2774d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
27751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
2776d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
27777976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
27787976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
27797976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
27807976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
27817976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
27827976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
2783d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
27841237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
27855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2786d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2787d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
2788f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
2789f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             QualType t, ExprValueKind VK, ExprObjectKind OK,
2790ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2791bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
2792bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
2793bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            lhs->containsUnexpandedParameterPack() ||
2794bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
27951237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
27961237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
27971237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
27981237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
27991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
28007976932a1c256d447316ffac58e9821417725e34Eli Friedman
280144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
280244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
280344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
28047976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
28057976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
28064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool isConditionTrue(const ASTContext &C) const;
28077976932a1c256d447316ffac58e9821417725e34Eli Friedman
28087976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
28097976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
28104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  Expr *getChosenSubExpr(const ASTContext &C) const {
28117976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
28127976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
28137976932a1c256d447316ffac58e9821417725e34Eli Friedman
28145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
281544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
28165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
281744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
28185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
281944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
282044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
282144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
282244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
282444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
282544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
28261237c673c07f9d827129ba02720108816abde562Ted Kremenek
2827d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
2828d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2829d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2830d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
2832d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2833d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
28341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28351237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
28361237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
28371237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2838d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
2839d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
28402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
28412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
28422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
28432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
28442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
28452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
28462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
28472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
28482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
28492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
28502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
2852bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false),
2853f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      TokenLoc(Loc) { }
28542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
285544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
285644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
285744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
28582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
28592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
286044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
28612d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
28622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
28632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
28642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
28652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
28672d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
28682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
28691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28702d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
28712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
28722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
28732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
28742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
287574626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg.
28767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
28775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
28782cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  TypeSourceInfo *TInfo;
28797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
28807c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
28812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
28822cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara            SourceLocation RPLoc, QualType t)
2883f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
2884bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           t->isDependentType(), false,
2885bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (TInfo->getType()->containsUnexpandedParameterPack() ||
2886bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            e->containsUnexpandedParameterPack())),
28872cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      Val(e), TInfo(TInfo),
28887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
28897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
289174626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  /// \brief Create an empty __builtin_va_arg expression.
2892d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2893d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
28945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
28955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
2896d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
2897d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
28982cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
28992cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
29002cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara
2901d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2902d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2904d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2905d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2906d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
29077c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
29087c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
29107c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
29117c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
29127c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
29137c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
29141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
29167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
29171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
29187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
29191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
29214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
29224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
29234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
29244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
29254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
29264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
29274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
29284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
2929196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
29304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
29314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
29324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
29334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
29344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
29354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
29364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
29374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
2938196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
29394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
29404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
29414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
29424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
29434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
29444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
29454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
29463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
29474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
29484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
29494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
2950196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
29514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
29524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
29534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
29544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
29554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
29564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
295766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
2958ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // FIXME: Eliminate this vector in favor of ASTContext allocation
2959709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef ASTVector<Stmt *> InitExprsTy;
2960709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprsTy InitExprs;
296166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
29621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
29644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
29654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
29664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29670bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
29680bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
29690bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
29700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2971a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
2972a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
2973a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
2974a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
297566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
2976709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2977709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek               Expr **initexprs, unsigned numinits,
2978ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek               SourceLocation rbraceloc);
2979d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2980d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
2981709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2982709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : Expr(InitListExprClass, Empty), InitExprs(C) { }
29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2984ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  unsigned getNumInits() const { return InitExprs.size(); }
29851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2986aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the set of initializers.
2987aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
2988aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
298916c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner  const Expr *getInit(unsigned Init) const {
2990c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
29914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
299266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
299416c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner  Expr *getInit(unsigned Init) {
2995c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
29964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
299766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
29981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
3000c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
30019e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
30029e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
3003c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
3004fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
3005709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  void reserveInits(ASTContext &C, unsigned NumInits);
30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
30084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
30094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
30104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
30114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
30124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
30134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
30144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
30154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
30164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
30174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
30184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
30194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
30204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
30214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
3022709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
3023c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
30240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
30250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
30260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
30270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
30280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
30290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
30300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
30310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
30320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
3033c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
3034c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
3035b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
3036b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
3037b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3039d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3040d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
3041d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
304287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
304387fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
30444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
30454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
30464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
30484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
30494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
30504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3051a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
30521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
3053d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
3054a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
3055a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
3056c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek  virtual SourceRange getSourceRange() const;
3057c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek
305866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
30591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
306066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
306166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
30621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
306366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
306466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
306566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3067709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::iterator iterator;
30688111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  typedef InitExprsTy::const_iterator const_iterator;
3069709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::reverse_iterator reverse_iterator;
30708111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
30711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3072ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator begin() { return InitExprs.begin(); }
30738111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_iterator begin() const { return InitExprs.begin(); }
3074ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator end() { return InitExprs.end(); }
30758111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_iterator end() const { return InitExprs.end(); }
3076ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
30778111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3078ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
30798111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_reverse_iterator rend() const { return InitExprs.rend(); }
308066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
308166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
308505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
308805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
30891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
309005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
309105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
309505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
3103ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
3104ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
3105ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
3106ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
3107ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
311105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3112eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
3114eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3119ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
3120ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
3121ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
3122ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
312605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
312705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3128ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
3129319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3130ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
3131eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
31329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
31339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3135d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
3136d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
3137d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
3138d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
314405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
314505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
314605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
314705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
314805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
31491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
315005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
315105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
31521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
315305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
315405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
315505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
315605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
315705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
315905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
316005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
316205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
316505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
31681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
316905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
317205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
317505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
317805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
317905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
318005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
318105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
3194ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
3195ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
319905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
320005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
320105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
320305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
320405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
320505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
320705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
320805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
320905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
321005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
321105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
321205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
321305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
321405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
321505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
32161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
321705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
321805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
321905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
322005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
322105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
322205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
322405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
322505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
322605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
322705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
322805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
322905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
323005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
323105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
323205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
323305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
323405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
323505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
323605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
323905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
324005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
324105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
324205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
324305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
324487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
324587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
324687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
324787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
324887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
324905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
325005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
325105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
325205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
325305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
325405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
325505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
325605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
325705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
325805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
325905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
326005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
326105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
326205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
326305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
326405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
326505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
326605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
326705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
326805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
326905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
327005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
32714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3272d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
3273d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3274d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
3275d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
3276d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
3277d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
32784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
32794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
32804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
32814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
32824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
32834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
328405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
328505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
328705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
328805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
328905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
3290eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
329105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3292d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3293d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
329405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
329505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
329605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
329705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
329805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
3299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
33011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
3302ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
330305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3304cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  typedef std::reverse_iterator<designators_iterator>
3305cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek          reverse_designators_iterator;
3306cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  reverse_designators_iterator designators_rbegin() {
3307cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return reverse_designators_iterator(designators_end());
3308cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  }
3309cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  reverse_designators_iterator designators_rend() {
3310cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return reverse_designators_iterator(designators_begin());
3311cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  }
3312cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek
3313711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3314711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3315c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void setDesignators(ASTContext &C, const Designator *Desigs,
3316319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                      unsigned NumDesigs);
3317d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
331805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
331905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
332005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
332105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
332205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
332305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
332405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3325d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
332605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
332705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
3328eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
3329eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
3330d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
333105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
333205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
33331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
333405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
333505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
333605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
333705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
333805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
333905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
334005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3341d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
3342d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
3343d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
3344d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
3345d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
3346d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3347d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
3348d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3349d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3350d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3351d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3352d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3353d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3354d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
3355d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3356d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3357d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3358d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3359d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3360d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3361ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
3362ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
3363319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3364ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
3365ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
336605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
336705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
336805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
33691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
337005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
337105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
337205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
337305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
337405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
33751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
33763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
33773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
33783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
33793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
33803498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
33811a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
33821a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
33833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
33841a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
33851a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
33861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
33873498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
3389f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
3390bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, false, false) { }
33913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
3392d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
3393d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
3394d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
3395d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
33961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
33983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
33993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
34003498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
34013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
34023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
34033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
34043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
34053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
34063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
34071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
340805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
340905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
34102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
34122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
34132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
34142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
34152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
34171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
34182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                unsigned numexprs, SourceLocation rparenloc);
34192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34202ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
342137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
34241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
34262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
34272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
34282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
34291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
34312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
34322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
34332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
34342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
343583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
34382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
34392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual SourceRange getSourceRange() const {
34412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
34421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
34432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
34441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
34452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
34462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
34471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
34492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_begin();
34502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_end();
345137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis
345260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
34533397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
34542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
34552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
34584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
34594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
34604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
3461a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3462a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
3463a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
3464a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3465a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
346673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
346773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
346873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
3469a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
3470a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
3471d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
3472a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
3473a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
3474f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
3475f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       IdentifierInfo &accessor, SourceLocation loc)
34760943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall    : Expr(ExtVectorElementExprClass, ty, VK,
34770943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
3478bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->isTypeDependent(), base->isValueDependent(),
3479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
3480d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
34811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3482d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
3483d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
3484d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
3485d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3486a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
3487a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
3488d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
3489d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3490d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
3491d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3492d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3493d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3494d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3495d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3496a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
3497a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
34981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3499a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
3500a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
3501a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3503a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3504a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
3505a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3507a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
3508a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3509a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
35101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35112140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
35122140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
35132140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
35141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
35161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
3517a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3518a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
35191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3520a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
3521a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
3522a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
3523a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
3524a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3525a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
352656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
35279c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
35284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
352956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
353056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
3531b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
35324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3533b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
3534f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
3535bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           ty->isDependentType(), false, false),
3536b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
35379c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
353884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
353984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
354084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
3541d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
354256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
354384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
354484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
354556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
354656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
354756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
354856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
35499c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
35509c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
355156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
35529c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
35539c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
355456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
355556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
355656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
3557b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
35585b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
3559b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
356084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3561b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
35621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
35639c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
35644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
35654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
35661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
35684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
35694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
35704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
35711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
35734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
35744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
35751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ValueDecl *D;
35764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
35777d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool IsByRef : 1;
35787d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool ConstQualAdded : 1;
357989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  Stmt *CopyConstructorVal;
35804eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3581f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  BlockDeclRefExpr(ValueDecl *d, QualType t, ExprValueKind VK,
3582f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   SourceLocation l, bool ByRef, bool constAdded = false,
3583a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor                   Stmt *copyConstructorVal = 0);
358494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
358594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
358694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
358794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
358894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
35891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
35914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
359294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
359394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
359494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
359594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
359694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
35974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
35981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
360094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
36011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36027d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool isConstQualAdded() const { return ConstQualAdded; }
36037d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setConstQualAdded(bool C) { ConstQualAdded = C; }
360489f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian
360589f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  const Expr *getCopyConstructorExpr() const
360689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    { return cast_or_null<Expr>(CopyConstructorVal); }
360789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  Expr *getCopyConstructorExpr()
360889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    { return cast_or_null<Expr>(CopyConstructorVal); }
360989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; }
361094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
36111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
36121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BlockDeclRefExprClass;
36134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
36144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
36174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
36184eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
36194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
36204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
36217cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// OpaqueValueExpr - An expression referring to an opaque object of a
36227cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// fixed type and value class.  These don't correspond to concrete
36237cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// syntax; instead they're used to express operations (usually copy
36247cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// operations) on values whose source is generally obvious from
36257cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// context.
36267cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallclass OpaqueValueExpr : public Expr {
36277cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  friend class ASTStmtReader;
36287cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallpublic:
3629f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  OpaqueValueExpr(QualType T, ExprValueKind VK, ExprObjectKind OK = OK_Ordinary)
3630f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(OpaqueValueExprClass, T, VK, OK,
3631bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           T->isDependentType(), T->isDependentType(), false) {
36327cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  }
36337cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
36347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  explicit OpaqueValueExpr(EmptyShell Empty)
36357cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall    : Expr(OpaqueValueExprClass, Empty) { }
36367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
36377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  virtual SourceRange getSourceRange() const;
36387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  virtual child_iterator child_begin();
36397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  virtual child_iterator child_end();
36407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
36417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  static bool classof(const Stmt *T) {
36427cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall    return T->getStmtClass() == OpaqueValueExprClass;
36437cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  }
36447cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall  static bool classof(const OpaqueValueExpr *) { return true; }
36457cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall};
36467cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall
36475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
36485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
36495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3650