Expr.h revision 663e380d7b2de2bbf20e886e05371195bea9adc4
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"
21709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h"
22409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h"
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
24525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
253b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
26b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h"
27c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
30590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
31c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
38409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CXXBaseSpecifier;
3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
41833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
42d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
447ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers.
457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlssontypedef UsuallyTinyPtrVector<const CXXBaseSpecifier> CXXBaseSpecifierArray;
467ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
54bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  virtual void ANCHOR(); // key function.
559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected:
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// TypeDependent - Whether this expression is type-dependent
57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
59898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ValueDependent - Whether this expression is value-dependent
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
65b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Increases the reference count for this expression.
7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// Invoke the Retain() operation when this expression
7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// is being shared by another owner.
7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  Expr *Retain() {
7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    Stmt::Retain();
7943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    return this;
8043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  }
811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
91905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
928320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
93f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
9677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
1070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValueDependent(bool VD) { ValueDependent = VD; }
1080b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setTypeDependent(bool TD) { TypeDependent = TD; }
1240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
137026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
138026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
139df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                              SourceRange &R2, ASTContext &Ctx) const;
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
15008ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
15176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
157fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
15886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
1592514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    LV_MemberFunction,
160e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    LV_SubObjCPropertySetting,
161e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    LV_ClassTemporary
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16328be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
16453202857c60214d80950a975e6e52aebf30bd16aEli Friedman
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and if it is a structure or union, does not have any member (including,
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
17044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
17144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
17244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
17344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
178fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
180ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1834f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1845daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
185ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
18686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
1872514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    MLV_MemberFunction,
188e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    MLV_SubObjCPropertySetting,
189e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    MLV_ClassTemporary
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
19144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
19244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief The return type of classify(). Represents the C++0x expression
1952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        taxonomy.
1962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  class Classification {
1972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
1982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The various classification results. Most of these mean prvalue.
1992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum Kinds {
2002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_LValue,
2012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_XValue,
2022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Function, // Functions cannot be lvalues in C.
2032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Void, // Void cannot be an lvalue in C.
2042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
2052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_MemberFunction, // An expression referring to a member function
2062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_SubObjCPropertySetting,
2072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_ClassTemporary, // A prvalue of class type
2082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_PRValue // A prvalue for any other reason, of any other type
2092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The results of modification testing.
2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum ModifiableType {
2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Untested, // testModifiable was false.
2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Modifiable,
2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_RValue, // Not modifiable because it's an rvalue
2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Function, // Not modifiable because it's a function; C++ only
2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NotBlockQualified, // Not captured in the closure
2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ConstQualified,
2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ArrayType,
2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_IncompleteType
2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  private:
2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    friend class Expr;
2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Kind;
2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Modifiable;
2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    explicit Classification(Kinds k, ModifiableType m)
2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      : Kind(k), Modifiable(m)
2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    {}
2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Classification() {}
2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Kinds getKind() const { return static_cast<Kinds>(Kind); }
2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    ModifiableType getModifiable() const {
2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      return static_cast<ModifiableType>(Modifiable);
2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    }
2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isLValue() const { return Kind == CL_LValue; }
2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isXValue() const { return Kind == CL_XValue; }
2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isGLValue() const { return Kind <= CL_XValue; }
2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isPRValue() const { return Kind >= CL_Function; }
2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isRValue() const { return Kind >= CL_XValue; }
2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief classify - Classify this expression according to the C++0x
2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        expression taxonomy.
2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// old lvalue vs rvalue. This function determines the type of expression this
2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// is. There are three expression types:
2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - lvalues are classical lvalues as in C++03.
2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - prvalues are equivalent to rvalues in C++03.
2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///   function returning an rvalue reference.
2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// lvalues and xvalues are collectively referred to as glvalues, while
2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// prvalues and xvalues together form rvalues.
2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// If a
2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification Classify(ASTContext &Ctx) const {
2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, 0);
2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief classifyModifiable - Classify this expression according to the
2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        C++0x expression taxonomy, and see if it is valid on the left side
2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        of an assignment.
2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// This function extends classify in that it also tests whether the
2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// expression is modifiable (C99 6.3.2.1p1).
2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \param Loc A source location that might be filled with a relevant location
2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///            if the expression is not modifiable.
2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, &Loc);
2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate:
2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic:
2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
28333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
28433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
28533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
28838d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
28938d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
291093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
292093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  bool refersToVectorElement() const;
293c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2942b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
2952b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
2962b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// but also int expressions which are produced by things like comparisons in
2972b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// C.
2982b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isKnownToHaveBooleanValue() const;
299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
304590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
305590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
307590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
3088070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
309590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
311c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
312c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
313c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isConstantInitializer(ASTContext &Ctx) const;
3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
31694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
3172d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
31894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
32194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
32294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
32594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
32694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
32794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
32894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
32994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
33094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
33194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
33294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
33394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
33494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
337e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
338e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // isGlobalLValue - Return true if the evaluated lvalue expression
339e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // is global.
340e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool isGlobalLValue() const;
341e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // hasSideEffects - Return true if the evaluated expression has
342e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // side effects.
343e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool hasSideEffects() const {
344e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara      return HasSideEffects;
345e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    }
34694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
34794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
3486ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
349019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
350019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
351019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
3525b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
3535b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
354cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// EvaluateAsBooleanCondition - Return true if this is a constant
355cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// which we we can fold and convert to a boolean condition using
356cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// any crazy technique that we want to.
357cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
358cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
3596ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
36045b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
36145b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
362c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
3636ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// HasSideEffects - This routine returns true for all those expressions
364c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// which must be evaluated each time and must not be optimization away
3656ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// or evaluated at compile time. Example is a function call, volatile
3666ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// variable read.
367393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian  bool HasSideEffects(ASTContext &Ctx) const;
368c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
36951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
37051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
37151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
37251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
373b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
374b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// with link time known address.
3751b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
3761b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
377e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
378e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
379e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
380ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
381ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// should cope with value-dependent expressions.
382ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  enum NullPointerConstantValueDependence {
383ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
384ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_NeverValueDependent = 0,
385c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
386ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression of integral or
387ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// dependent type should be considered a null pointer constant.
388ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNull,
389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
390ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression should be considered
391ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// to never be a null pointer constant.
392ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNotNull
393ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  };
394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
395efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
396efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
397efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
398ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isNullPointerConstant(ASTContext &Ctx,
399ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                             NullPointerConstantValueDependence NPC) const;
400efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
40144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
403102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4054e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
4074e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
4084e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
4092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  Expr *IgnoreParens();
41056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
41156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
41227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
41356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4152fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
4162fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// ParenExpr or ImplicitCastExprs, returning their operand.
4172fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *IgnoreParenImpCasts();
4182fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
419ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
420ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
421ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
422ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4246eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether this expression is a default function argument.
4256eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
4266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Default arguments are implicitly generated in the abstract syntax tree
427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// by semantic analysis for function calls, object constructions, etc. in
4286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
4296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// this routine also looks through any implicit casts to determine whether
4306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// the expression is a default argument.
4316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool isDefaultArgument() const;
432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4332f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief Determine whether this expression directly creates a
4342f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object (of class type).
4352f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  bool isTemporaryObject() const { return getTemporaryObject() != 0; }
4362f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
4372f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief If this expression directly creates a temporary object of
4382f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// class type, return the expression that actually constructs that
4392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object.
4402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  const Expr *getTemporaryObject() const;
4412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
4422b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const Expr *IgnoreParens() const {
4434e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
4444e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
44556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
44656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
44756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
448ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
449ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
450ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
453898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
454898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
467a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the
468a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort".
469a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier {
470a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The nested name specifier.
471a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *NNS;
472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source range covered by the nested name specifier.
474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange Range;
475a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
476a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
477a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g.,
478a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>".
479a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList {
480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the left angle bracket ('<');
481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation LAngleLoc;
482c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the right angle bracket ('>');
484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation RAngleLoc;
485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The number of template arguments in TemplateArgs.
487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The actual template arguments (if any) are stored after the
488a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// ExplicitTemplateArgumentList structure.
489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned NumTemplateArgs;
490c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
491a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
492833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc *getTemplateArgs() {
493833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
495c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
496a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
497833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
499a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
500d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
501d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void initializeFrom(const TemplateArgumentListInfo &List);
502d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyInto(TemplateArgumentListInfo &List) const;
5038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static std::size_t sizeFor(unsigned NumTemplateArgs);
504d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
506c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  enum {
511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
512a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has a C++ nested-name-specifier.
513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasQualifierFlag = 0x01,
514c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has an explicit C++ template argument list.
516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasExplicitTemplateArgumentListFlag = 0x02
517a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // DecoratedD - The declaration that we are referencing, plus two bits to
520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // indicate whether (1) the declaration's name was explicitly qualified and
521c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // (2) the declaration's name was followed by an explicit template
522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // argument list.
523dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // Loc - The location of the declaration name itself.
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
5279e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NameQualifier *getNameQualifier() {
5302cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
532c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
533a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<NameQualifier *> (this + 1);
534a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
535c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
536a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
537a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const NameQualifier *getNameQualifier() const {
538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
542a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
5442cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0)
545a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
546c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5472cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
549c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                                      getNameQualifier() + 1);
552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
553c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
555a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList();
558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
559c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
561dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall              ValueDecl *D, SourceLocation NameLoc,
562d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall              const TemplateArgumentListInfo *TemplateArgs,
5630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor              QualType T);
564663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
565663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
566663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  explicit DeclRefExpr(EmptyShell Empty)
567663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    : Expr(DeclRefExprClass, Empty) { }
568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5690da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// \brief Computes the type- and value-dependence flags for this
5700da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// declaration reference expression.
5710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  void computeDependence();
5729e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
574dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
5750da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
5760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
5770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static DeclRefExpr *Create(ASTContext &Context,
580a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             NestedNameSpecifier *Qualifier,
581a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceRange QualifierRange,
582dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                             ValueDecl *D,
583a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceLocation NameLoc,
5840da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             QualType T,
5850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             const TemplateArgumentListInfo *TemplateArgs = 0);
586663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
587663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
588663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  static DeclRefExpr *CreateEmpty(ASTContext &Context,
589663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis                                  bool HasQualifier, unsigned NumTemplateArgs);
590c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
591dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
592dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
593dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
594904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
5959e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
5960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
597a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  virtual SourceRange getSourceRange() const;
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
599a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
600a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// C++ nested-name-specifier, e.g., \c N::foo.
601a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
603a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief If the name was qualified, retrieves the source range of
604a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// the nested-name-specifier that precedes the name. Otherwise,
605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returns an empty source range.
606a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange getQualifierRange() const {
607a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceRange();
609c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
610a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->Range;
611a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
612c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
613c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief If the name was qualified, retrieves the nested-name-specifier
614a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that precedes the name. Otherwise, returns NULL.
615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *getQualifier() const {
616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
617a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
618c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
619a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->NNS;
620a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
622a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determines whether this member expression actually had a C++
623a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasExplicitTemplateArgumentList() const {
625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
626a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
627d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
628d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
629d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
630d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
631d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
632d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
633d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
634c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
635a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the left angle bracket following the
636a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member name ('<'), if any.
637a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getLAngleLoc() const {
638a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
639a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
640c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
641a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
642a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
643c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
644a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments provided as part of this
645a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
646833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
647a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
648a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
649c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
650a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
651a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
652c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
653a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
655a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned getNumTemplateArgs() const {
656a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
657a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
658c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
659a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
660a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
661c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
662a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the right angle bracket following the
663a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template arguments ('>').
664a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getRAngleLoc() const {
665a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
666a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
667c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
668a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
669a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
670c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
67299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    return T->getStmtClass() == DeclRefExprClass;
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
67777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
67877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
679663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
680663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  friend class PCHStmtReader;
681663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  friend class PCHStmtWriter;
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
684d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
685d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
686227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
687227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
688227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
689227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
690848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunction,
691848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
692848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// 'virtual' keyword is omitted for virtual member functions.
693848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunctionNoVirtual
694227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
696227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
697227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
698227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
699227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
701c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : Expr(PredefinedExprClass, type, type->isDependentType(),
702773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson           type->isDependentType()), Loc(l), Type(IT) {}
7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
70617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
70717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
708227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
70917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
71017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
71117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
71217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
71317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
714848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
7153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
716227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
717227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
720227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
721d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
72477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
72577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
726227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
727227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
7352333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
738a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
7390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IntegerLiteral(EmptyShell Empty)
7410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
7420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
746313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
747313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
748313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
7490b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
7500b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
7510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
75877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
75977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
765c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
768c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
7692333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
7702333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsWide(iswide) {
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
7730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
7740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
7750b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
776018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
777c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
7781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7830b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
7840b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
7850b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
7860b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
79177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
79277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
79377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
79477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
798525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
799720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  FloatingLiteral(const llvm::APFloat &V, bool isexact,
803720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
8042333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
8052333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsExact(isexact), Loc(L) {}
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
80717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit FloatingLiteral(EmptyShell Empty)
80917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
81017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
811c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
81217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
81317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
814720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
81517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
816c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
817da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
818da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
819da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
820da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
82317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
82417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
83377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
83477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8375d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
8385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
8395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
8405d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
8415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
8425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
8435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
8445d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
8455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
8462333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
848cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
850cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
851cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
8535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
854cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
855cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8565d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
8595d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
8605d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8625d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
8635d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
8645d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
8655d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
8665d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
867e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
868e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
869e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
870a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
871c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
872c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
873690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
874690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
8758bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
876690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
877c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
878c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
879c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
880c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
881c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
882c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
887726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
888726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
8892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
8902333f7727f97018d6742e1e0938133bcfad967abEli Friedman  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
89242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
89342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
89442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8962085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
8972085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
8982085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
8992085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
900a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
9012085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
9022085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static StringLiteral *Create(ASTContext &C, const char *StrData,
9042085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
9052085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
9062085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
9072085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
908a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
909673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
910673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
911673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
912b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  llvm::StringRef getString() const {
913b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return llvm::StringRef(StrData, ByteLength);
914b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
915b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  // FIXME: These are deprecated, replace with StringRef.
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
918673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
919673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
920b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void setString(ASTContext &C, llvm::StringRef Str);
921673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
923673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
924673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
9258d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
926b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    llvm::StringRef Str = getString();
927b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
928b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
92933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
93033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
93133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
932726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
933726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
934726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
9351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
936726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
937726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
938726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
939726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
9401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
941673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
942673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
943673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
944673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
945b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
946b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
947b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
95777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
95877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
95977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
9665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
969898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           val->isTypeDependent(), val->isValueDependent()),
971898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
973c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
975c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
976c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
9775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
9785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
979c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
980c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
981866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
983313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
984313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
985c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
986313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
987313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
988313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
989c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
990313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
9911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
99777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
99877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
10030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
1005dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1006dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
1007dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1008dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
1009dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
1010dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
1011dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
101273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   subexpression is a compound literal with the various MemberExpr and
10148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   ArraySubscriptExpr's applied to it. (This is only used in C)
101573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
101813d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
102673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
102773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
10305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
10369103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
10379103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           input->isValueDependent()),
10399103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
10430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
10440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
10460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
10470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
10485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
10490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
10500b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
10530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
10540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
10562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
10572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
10582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10605a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
10612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
10622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
10632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
10645a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
10655a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
10675d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
10695a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1077bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
1078bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
1079bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1080bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1081bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1082bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
1083bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1084bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
109877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
109977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
110077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
11048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given:
11058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code
11068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S {
11078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   float f;
1108c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   double d;
11098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
11108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T {
11118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   int i;
11128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   struct S s[10];
11138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
11148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode
1115c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
11168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr {
11188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
11198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
11208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  class OffsetOfNode {
11218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
11228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The kind of offsetof node we have.
11238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum Kind {
1124cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An index into an array.
11258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Array = 0x00,
1126cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field.
11278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Field = 0x01,
1128cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field in a dependent type, known only by its name.
1129cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Identifier = 0x02,
1130cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An implicit indirection through a C++ base class, when the
1131cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// field found is in a base class.
1132cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Base = 0x03
11338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    };
11348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  private:
11368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum { MaskBits = 2, Mask = 0x03 };
1137c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The source range that covers this part of the designator.
11398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange Range;
1140c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The data describing the designator, which comes in three
11428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// different forms, depending on the lower two bits.
1143c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - An unsigned index into the array of Expr*'s stored after this node
11448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     in memory, for [constant-expression] designators.
11458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - A FieldDecl*, for references to a known field.
11468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - An IdentifierInfo*, for references to a field with a given name
11478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     when the class type is dependent.
1148c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1149cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    ///     base class.
11508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    uintptr_t Data;
1151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
11538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an array element.
1154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
11558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation RBracketLoc)
11568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1157c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to a field.
1159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
11608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1161c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
11628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1163c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an identifier.
11658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
11668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1167c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
11688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1169cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1170cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1171cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1172cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Determine what kind of offsetof node this is.
1175c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Kind getKind() const {
11768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return static_cast<Kind>(Data & Mask);
11778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1178c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For an array element node, returns the index into the array
11808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// of expressions.
11818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    unsigned getArrayExprIndex() const {
11828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Array);
11838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return Data >> 2;
11848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
11858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field offsetof node, returns the field.
11878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    FieldDecl *getField() const {
11888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Field);
1189cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
11908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1191c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field or identifier offsetof node, returns the name of
11938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the field.
11948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    IdentifierInfo *getFieldName() const;
1195c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1196cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief For a base class node, returns the base specifier.
1197cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    CXXBaseSpecifier *getBase() const {
1198cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      assert(getKind() == Base);
1199c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1200cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    }
1201c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Retrieve the source range that covers this offsetof node.
12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///
12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// For an array element node, the source range contains the locations of
12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
1206c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// contains the location of the period (if there is one) and the
12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// identifier.
12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange getRange() const { return Range; }
12098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
12108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
1212c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation OperatorLoc, RParenLoc;
12148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Base type;
12158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *TSInfo;
12168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-components (i.e. instances of OffsetOfNode).
12178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumComps;
12188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
12198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumExprs;
1220c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1221c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  OffsetOfExpr(ASTContext &C, QualType type,
12228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1223c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt               OffsetOfNode* compsPtr, unsigned numComps,
12248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               Expr** exprsPtr, unsigned numExprs,
12258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation RParenLoc);
12268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
12288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(OffsetOfExprClass, EmptyShell()),
1229c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
12308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1232c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1234c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1235c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              OffsetOfNode* compsPtr, unsigned numComps,
12368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              SourceLocation RParenLoc);
12388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *CreateEmpty(ASTContext &C,
12408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   unsigned NumComps, unsigned NumExprs);
12418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getOperatorLoc - Return the location of the operator.
12438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
12448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
12458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Return the location of the right parentheses.
12478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
12488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1249c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
12518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TSInfo;
12528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setTypeSourceInfo(TypeSourceInfo *tsi) {
12548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TSInfo = tsi;
12558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1256c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const OffsetOfNode &getComponent(unsigned Idx) {
12588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
12598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
12608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setComponent(unsigned Idx, OffsetOfNode ON) {
12638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
12648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1266c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumComponents() const {
12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumComps;
12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr* getIndexExpr(unsigned Idx) {
12728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumExprs && "Subscript out of range");
12738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<Expr **>(
12748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
12758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setIndexExpr(unsigned Idx, Expr* E) {
12788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
12798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<Expr **>(
12808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
12818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumExpressions() const {
12848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumExprs;
12858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual SourceRange getSourceRange() const {
12888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(OperatorLoc, RParenLoc);
12898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_begin();
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_end();
13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
13030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
13040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
13050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
13060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
1307d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
1308a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *Ty;
1309d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
1310d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
131242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
131342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
131442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
131542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1317a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
13180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
13190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
13202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
1321ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
13222850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
1323a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall           TInfo->getType()->isDependentType()),
1324ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1325a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1326ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
1327ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1329ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
1330ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
1331ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
1332ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1333ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
1334ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
1335ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1336ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
1337d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
13380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
13390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
13400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
13410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
13420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
13440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
13450b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
13460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
13470518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
13485ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getArgumentTypeInfo()->getType();
13495ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  }
1350a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *getArgumentTypeInfo() const {
13510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
13525ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return Argument.Ty;
13530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1354caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
13550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1356d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
13570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1358caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
1359caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1360caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
13610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
13620b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1363a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  void setArgument(TypeSourceInfo *TInfo) {
1364a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    isType = true;
13660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
13670b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
13680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
13690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
13700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
13710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
13720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
13730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
137476e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
13750b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
13760b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
13770b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
13780b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1379866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1380866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
1381866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
1382866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SizeOfAlignOfExprClass;
13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
13881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
138977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
139077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
139177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
140077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
140573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
14062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
14072850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
14082850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
14092850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
141073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
141173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
141273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1414cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
1415cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
1416cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
1417cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
14182324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
14192324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
14202324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
14212324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
14222324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
142333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
142433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
142533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
142633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
14275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
14285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1429cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1430cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
14315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
14325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1433cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
14365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
143777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
14405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
14412324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
14445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
14452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
14485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
145277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1455026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1456cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1457cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
14585cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
14641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
146677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
146777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1471b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1473b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
1475b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1476b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
147877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
14795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1483b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
1484b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
1485668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1486668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
148742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
148842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
14931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14941f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
1495ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
14961f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1497668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
14981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
15005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
150118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
1502a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1503d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  Decl *getCalleeDecl();
1504d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  const Decl *getCalleeDecl() const {
1505d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return const_cast<CallExpr*>(this)->getCalleeDecl();
1506d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
1507d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
1508a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1509a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
1510bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  const FunctionDecl *getDirectCallee() const {
1511bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
1512bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
1513a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
15215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
15255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1528934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
1529934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
1530934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
1531934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
1532934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1534d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
1535d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
1536d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
15378189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
15405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1542d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1543d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
15445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
15455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1551cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1552cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
15533c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
15576dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
15586dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1560d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
15611f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1562866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
156477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
15655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
15684bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCallExprConstant &&
15694bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCallExprConstant;
15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
157288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
157377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
157477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
157577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1578ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
15816bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// Extra data stored in some member expressions.
15826bb8017bb9e828d118e15e59d71c66bba323c364John McCall  struct MemberNameQualifier : public NameQualifier {
1583161755a09898c95d21bfff33707da9ca41cd53c5John McCall    DeclAccessPair FoundDecl;
15846bb8017bb9e828d118e15e59d71c66bba323c364John McCall  };
15856bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1586ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1587ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
15885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1590ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1591ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
1592f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *MemberDecl;
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1594ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1597ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
159883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
16016bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
16026bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// declaration.  When true, a MemberNameQualifier
1603c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
16046bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool HasQualifierOrFoundDecl : 1;
16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1606c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief True if this member expression specified a template argument list
1607c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1608c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure (and its TemplateArguments) are allocated immediately after
1609c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier, after
16106bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// the MemberNameQualifier structure.
1611c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  bool HasExplicitTemplateArgumentList : 1;
16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
161383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
16146bb8017bb9e828d118e15e59d71c66bba323c364John McCall  MemberNameQualifier *getMemberQualifier() {
16156bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(HasQualifierOrFoundDecl);
16166bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return reinterpret_cast<MemberNameQualifier *> (this + 1);
161783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
161883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
161983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
16206bb8017bb9e828d118e15e59d71c66bba323c364John McCall  const MemberNameQualifier *getMemberQualifier() const {
1621c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1622c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1624c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1625c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1626c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1627c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
162883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16306bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1631c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1633c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
1634c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                                                      getMemberQualifier() + 1);
1635c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1637c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1638c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1639c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1640c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
164183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1644f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1645f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman             SourceLocation l, QualType ty)
16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(MemberExprClass, ty,
1647ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson           base->isTypeDependent(), base->isValueDependent()),
164883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
16496bb8017bb9e828d118e15e59d71c66bba323c364John McCall      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1650510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
16511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
165283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                            NestedNameSpecifier *qual, SourceRange qualrange,
1653161755a09898c95d21bfff33707da9ca41cd53c5John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
1654c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation l,
1655d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                            const TemplateArgumentListInfo *targs,
1656c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            QualType ty);
16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
165888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
16595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
166057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
166157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
166257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
166357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
166457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
1665f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *getMemberDecl() const { return MemberDecl; }
1666f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
16671f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
16686bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// \brief Retrieves the declaration found by lookup.
1669161755a09898c95d21bfff33707da9ca41cd53c5John McCall  DeclAccessPair getFoundDecl() const {
16706bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1671161755a09898c95d21bfff33707da9ca41cd53c5John McCall      return DeclAccessPair::make(getMemberDecl(),
1672161755a09898c95d21bfff33707da9ca41cd53c5John McCall                                  getMemberDecl()->getAccess());
16736bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return getMemberQualifier()->FoundDecl;
16746bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
16756bb8017bb9e828d118e15e59d71c66bba323c364John McCall
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
16770979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
16780979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
16796bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool hasQualifier() const { return getQualifier() != 0; }
16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
168283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
168383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// returns an empty source range.
16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getQualifierRange() const {
16856bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
168683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return SourceRange();
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->Range;
168983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
169283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
169383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
16956bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
169683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
16971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
169883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->NNS;
169983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
1700c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1701c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
1702c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
1703d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  bool hasExplicitTemplateArgumentList() const {
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return HasExplicitTemplateArgumentList;
1705c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1707d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1708d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1709d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1710d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
1711d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
1712d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1713c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
1715c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member name ('<'), if any.
17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1717c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1718c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1720c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
1721c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1723c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1724c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
1725833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1726c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1729c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
1730c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1732c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1733c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
1735c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1738c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1739c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
1742c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template arguments ('>').
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
1744c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1745c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1747c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
1748c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
17511f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
17521f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1753ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1754ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1755026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
17561f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
17575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
175972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
176072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
1761c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    SourceLocation EndLoc = MemberLoc;
1762c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (HasExplicitTemplateArgumentList)
1763c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      EndLoc = getRAngleLoc();
17641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
176572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
176672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
1767c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceRange(MemberLoc, EndLoc);
1768c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return SourceRange(BaseLoc, EndLoc);
17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
177483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
17755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17781237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17791237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17801237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
17815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
1784aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1785aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
17860fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
17870fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
17880fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
17890fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
17901d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
17911d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// The type as written.  This can be an incomplete array type, in
17921d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// which case the actual expression type will be different.
179342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *TInfo;
17945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1795e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1796aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
17972333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can compound literals be value-dependent?
179842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
17991d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall                      QualType T, Expr *init, bool fileScope)
18001d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    : Expr(CompoundLiteralExprClass, T,
180142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall           tinfo->getType()->isDependentType(), false),
180242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
18031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1804ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1805ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1806ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1807ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
18085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
18095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1810ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1811e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1812e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1813ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1814ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
18150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1816ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1817ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
181842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
181942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
182042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall
182173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
18220fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
18230fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
18240fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
18250fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
182673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
18270fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
182873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1829aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
18311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
1832aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1833aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18351237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
18361237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
18371237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1838aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1839aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
184049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
184149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
184249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
184349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
18440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
1845cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
1846cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  /// CastKind - the kind of cast this represents.
1847cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  enum CastKind {
1848cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_Unknown - Unknown cast kind.
18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// FIXME: The goal is to get rid of this and make all casts have a
1850cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// kind so that the AST client doesn't have to try to figure out what's
1851cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// going on.
1852cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_Unknown,
18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1854cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_BitCast - Used for reinterpret_cast.
1855cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_BitCast,
18561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1857cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_NoOp - Used for const_cast.
18583503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    CK_NoOp,
18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
186011de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    /// CK_BaseToDerived - Base to derived class casts.
186111de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    CK_BaseToDerived,
186211de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson
18633503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    /// CK_DerivedToBase - Derived to base class casts.
1864714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    CK_DerivedToBase,
18651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
186623cba801e11b03929c44f8cf54578305963a3476John McCall    /// CK_UncheckedDerivedToBase - Derived to base class casts that
186723cba801e11b03929c44f8cf54578305963a3476John McCall    /// assume that the derived pointer is not null.
186823cba801e11b03929c44f8cf54578305963a3476John McCall    CK_UncheckedDerivedToBase,
186923cba801e11b03929c44f8cf54578305963a3476John McCall
1870714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    /// CK_Dynamic - Dynamic cast.
18714d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    CK_Dynamic,
18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18734d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    /// CK_ToUnion - Cast to union (GCC extension).
1874112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    CK_ToUnion,
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1876112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    /// CK_ArrayToPointerDecay - Array to pointer decay.
187727a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_ArrayToPointerDecay,
18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1879b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    // CK_FunctionToPointerDecay - Function to pointer decay.
1880b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    CK_FunctionToPointerDecay,
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188227a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_NullToMemberPointer - Null pointer to member pointer.
188327a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_NullToMemberPointer,
18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188527a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
188627a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// member pointer in derived class.
18879099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian    CK_BaseToDerivedMemberPointer,
18889099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian
18891a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
18901a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// member pointer in base class.
18911a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    CK_DerivedToBaseMemberPointer,
1892c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// CK_UserDefinedConversion - Conversion using a user defined type
189458d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian    /// conversion function.
18957fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    CK_UserDefinedConversion,
18967fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian
18977fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    /// CK_ConstructorConversion - Conversion by constructor
18987f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_ConstructorConversion,
1899c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19007f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_IntegralToPointer - Integral to pointer
19017f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_IntegralToPointer,
1902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
19037f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_PointerToIntegral - Pointer to integral
1904ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    CK_PointerToIntegral,
1905c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1906ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    /// CK_ToVoid - Cast to void.
190716a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    CK_ToVoid,
1908c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
190916a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    /// CK_VectorSplat - Casting from an integer/floating type to an extended
1910c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// vector type with the same element type as the src type. Splats the
1911f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson    /// src expression into the destination expression.
191282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_VectorSplat,
1913c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
191482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralCast - Casting between integral types of different size.
191582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralCast,
191682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson
191782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralToFloating - Integral to floating point.
191882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralToFloating,
1919c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
192082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingToIntegral - Floating point to integral.
192182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_FloatingToIntegral,
1922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
192382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingCast - Casting between floating types of different size.
1924bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    CK_FloatingCast,
1925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1926bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    /// CK_MemberPointerToBoolean - Member pointer to boolean
192792ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    CK_MemberPointerToBoolean,
192892ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian
1929c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
193092ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    /// pointer
19313b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToObjCPointerCast,
1932c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
19333b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    /// pointer
19343b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToBlockPointerCast
1935bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson
1936cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  };
19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1938cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
1939cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind Kind;
19400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
1941409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
19427ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// BasePath - For derived-to-base and base-to-derived casts, the base array
19437ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// contains the inheritance path.
1944f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson  CXXBaseSpecifierArray BasePath;
19457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
19467ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  void CheckBasePath() const {
1947409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG
1948409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    switch (getCastKind()) {
19495cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    case CK_DerivedToBase:
1950cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_UncheckedDerivedToBase:
1951cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_DerivedToBaseMemberPointer:
1952409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerived:
1953409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerivedMemberPointer:
1954f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      assert(!BasePath.empty() && "Cast kind should have a base path!");
1955f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      break;
1956409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1957409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    // These should not have an inheritance path.
1958409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Unknown:
1959409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BitCast:
1960409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NoOp:
1961409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Dynamic:
1962409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToUnion:
1963409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ArrayToPointerDecay:
1964409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FunctionToPointerDecay:
1965409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NullToMemberPointer:
1966409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_UserDefinedConversion:
1967409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ConstructorConversion:
1968409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToPointer:
1969409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_PointerToIntegral:
1970409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToVoid:
1971409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_VectorSplat:
1972409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralCast:
1973409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToFloating:
1974409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingToIntegral:
1975409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingCast:
1976409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_MemberPointerToBoolean:
1977409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToObjCPointerCast:
1978409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToBlockPointerCast:
19795cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson      assert(BasePath.empty() && "Cast kind should not have a base path!");
1980409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson      break;
1981409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
1982409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif
1983409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
1984409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
19850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
1986409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
1987f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson           CXXBaseSpecifierArray BasePath) :
1988898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1991898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1992898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1993898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType() || (op && op->isValueDependent())),
19957ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    Kind(kind), Op(op), BasePath(BasePath) {
19967ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson      CheckBasePath();
1997409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
19981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1999087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CastExpr(StmtClass SC, EmptyShell Empty)
2001087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2003a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson  virtual void DoDestroy(ASTContext &C);
2004a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson
20050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
2006cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind getCastKind() const { return Kind; }
2007cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  void setCastKind(CastKind K) { Kind = K; }
2008f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
2009f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
20100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
20110835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2012087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
2013087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
20146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
20156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// code, looking through any implicit casts or other intermediate nodes
20166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// introduced by semantic analysis.
20176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *getSubExprAsWritten();
20186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *getSubExprAsWritten() const {
20196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
20206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
202141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
2022fc89c31a329eb6b36c6dbd8b7cb945d1a831650eAnders Carlsson  const CXXBaseSpecifierArray& getBasePath() const { return BasePath; }
20230745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis        CXXBaseSpecifierArray& getBasePath()       { return BasePath; }
202441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20264bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCastExprConstant &&
20274bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCastExprConstant;
20280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
20290835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20310835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
20320835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
20330835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
20340835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
20350835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
203649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
203749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
203849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
203949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
204049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
2041bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
2042bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
2043bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
2044bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
2045bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
2046bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
2047bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
2049bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
2050bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
2051bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
20520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
2053eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
2054eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
2055eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
205649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
2057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
2058f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson                   CXXBaseSpecifierArray BasePath, bool Lvalue)
2059c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath),
20607ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    LvalueCast(Lvalue) { }
206190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
2062087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitCastExpr(EmptyShell Shell)
2064087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
2065087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
20660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
20670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
20680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
206990045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
2070eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
2071eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
2072eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
2073eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
2074eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
2075eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
207849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
207949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
208049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
208149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
208249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
20831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
208449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
208549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
208649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
208749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
208849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
208949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
209149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
209249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
209349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
209449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
209549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
209649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
209749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
20980835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
20999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// TInfo - Source type info for the (written) type
21009d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// this expression is casting to.
21019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *TInfo;
210249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
210349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
2104c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
210541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   Expr *op, CXXBaseSpecifierArray BasePath,
210641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   TypeSourceInfo *writtenTy)
210741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CastExpr(SC, exprTy, kind, op, BasePath), TInfo(writtenTy) {}
210849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
2109db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
2111db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
2112db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
211349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
21149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// getTypeInfoAsWritten - Returns the type source info for the type
21159d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// that this expression is casting to.
21169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
21179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
21189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
211949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
212049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
21219d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  QualType getTypeAsWritten() const { return TInfo->getType(); }
212249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
21231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21244bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt     return T->getStmtClass() >= firstExplicitCastExprConstant &&
21254bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt            T->getStmtClass() <= lastExplicitCastExprConstant;
212649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
212749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
212849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
212949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
21306eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
213149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
213249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
21336eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
2134b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2135b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
213841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
213941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 SourceLocation l, SourceLocation r)
214041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, BasePath,
214141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy), LPLoc(l), RPLoc(r) {}
214249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
2143db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CStyleCastExpr(EmptyShell Shell)
2145db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
2146db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2147b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
2148db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2149db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2150b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
2151db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2152db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
2154b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
21585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21596eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
21605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
21633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
21643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
21653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
21663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
21673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
21683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
21693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
21703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
21713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
21723fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
21733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
21743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
21753fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
21763fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
21773fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
21783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
21793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
21805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
21815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
21835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
218403d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
2185224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
21865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
21875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
21895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
21905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
21925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
21965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
21995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
22005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
22015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
22025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
22035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
220417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
220517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
22065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
220717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
220817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
221117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
221217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
2213898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
2214898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
22151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           lhs->isValueDependent() || rhs->isValueDependent()),
2216898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
22171237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22181237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2223db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
22241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
2225db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
2226db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
222717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
2228db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2229db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
22305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
2231db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
2232db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
22335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2234db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
22355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2236db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2237db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
22395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
22405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
22435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
22445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2246063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
2247063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
2248063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2249063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2250063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
2251063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
2252063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2253063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
22545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
22555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
2256ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose  static bool isAdditiveOp(Opcode Opc) { return Opc == Add || Opc == Sub; }
2257ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose  bool isAdditiveOp() const { return isAdditiveOp(Opc); }
225840a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
225940a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  bool isShiftOp() const { return isShiftOp(Opc); }
2260aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2261aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
2262aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isBitwiseOp() const { return isBitwiseOp(Opc); }
2263f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
2264f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
2265f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
2266f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
22671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
2268f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
22691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2270aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
2271aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isComparisonOp() const { return isComparisonOp(Opc); }
2272aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2273f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
2274f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
2275f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
22765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
22785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
22814bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return S->getStmtClass() >= firstBinaryOperatorConstant &&
22824bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           S->getStmtClass() <= lastBinaryOperatorConstant;
22835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
22851237c673c07f9d827129ba02720108816abde562Ted Kremenek
22861237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
22871237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
22881237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
22891237c673c07f9d827129ba02720108816abde562Ted Kremenek
22905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
229117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
22922333f7727f97018d6742e1e0938133bcfad967abEli Friedman                 SourceLocation opLoc, bool dead)
22932333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CompoundAssignOperatorClass, ResTy,
22942333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
22952333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isValueDependent() || rhs->isValueDependent()),
22962333f7727f97018d6742e1e0938133bcfad967abEli Friedman      Opc(opc), OpLoc(opLoc) {
22971237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22981237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2300ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
23011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
2302ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
23035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
23065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
23075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
23085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
23095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
23105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
23115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
2312ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
2313ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
23145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
2316ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
2317ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
231817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
231917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
2320ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
2321ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
23235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
23245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2326ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
2327ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
2328ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2329ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2330ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
2331ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
2332ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2333ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
2334ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2335ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2336ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
2337ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
2338ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
23395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
23401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
23411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
23425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
23491237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
23505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
235147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
23525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
235347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
235447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                      SourceLocation CLoc, Expr *rhs, QualType t)
2355898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
2356898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
2357898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
2358898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
2359898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
23601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (cond->isValueDependent() ||
2361898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
236247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor            (rhs && rhs->isValueDependent()))),
236347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      QuestionLoc(QLoc),
236447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      ColonLoc(CLoc) {
23651237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
23661237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
23671237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
23681237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
23695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2370ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
2371ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
2372ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
2373ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2374395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
2375395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
23765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2377ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
2378395a2abf0028968d85958610e393e067885dc14fTed Kremenek
2379395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2380395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
2381395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
2382395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
2383395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
23841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //  is only evaluated once.
2385395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
23865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2387395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
23881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2389395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2390395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
23915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2394ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2395ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
23965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2397ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
23985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
239947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
240047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
240147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
240247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
240347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
240447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
24055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
24065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
24075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
24091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
24105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24131237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24141237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24151237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24186481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
24196481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
24205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
24215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24236481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
24246481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
24252333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(AddrLabelExprClass, t, false, false),
24262333f7727f97018d6742e1e0938133bcfad967abEli Friedman      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24287d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
24291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
24307d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
24317d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
24327d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
24337d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
24347d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
24357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
24367d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
24375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
24395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
24427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
24437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
24445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24476481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24491237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24501237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24511237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
24525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2453ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2454ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2455ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2456ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
2457ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
24585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
2459ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
2460ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
24612333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Does type-dependence need to be computed differently?
2462d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
2463d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
24642333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(StmtExprClass, T, T->isDependentType(), false),
24652333f7727f97018d6742e1e0938133bcfad967abEli Friedman    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24676a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
24686a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
24696a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
24705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
24715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
24726a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
24736a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
2474ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
2475ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
2476ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2478026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
24796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2480026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
24816a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
24821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2483ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
2485ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
2486ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
24871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24881237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24891237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24901237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2491ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
2492ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2493dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2494d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
2495d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
2496d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
2497d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
2498d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
2499d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
2500363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2501d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
25031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType t1, QualType t2, SourceLocation RP) :
25042333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(TypesCompatibleExprClass, ReturnType, false, false),
25052333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2506d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
250744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
250844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
250944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
251044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
25117f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
251244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
25137f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
251444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
25151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
251644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
251744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
25181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
251944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
252044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2522d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
2523363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2524d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2525d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == TypesCompatibleExprClass;
2527d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2528d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25301237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
25311237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
25321237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2533d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
2534d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
2535d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
2536d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
2537d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
2538d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
2539d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
2540d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
2541d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
2542d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
2543d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2544d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
2545d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
2546d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
2547d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
25485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
2549d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
2550d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2551888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected:
25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
2553888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2554d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
25552333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
25562333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // to be computed differently?
2557a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
25581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
25591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SourceLocation RP) :
25602333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
25612333f7727f97018d6742e1e0938133bcfad967abEli Friedman    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2563a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman    SubExprs = new (C) Stmt*[nexpr];
2564d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
2565d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
2566d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
256794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
256894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
25691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
257094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
257194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
257294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
257394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
257594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
257694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
257794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2578d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
2579d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
2580d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2581d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
2583d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2584d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2586888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  ~ShuffleVectorExpr() {}
25871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2588d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2589d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
2590d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
2591d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2593d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
2594d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
2595d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
25965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2597d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2598d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
2599d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
26005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2601d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
26021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2603888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
260494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2605dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2606dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
26079a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2608d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2610d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
2611d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
2612d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
2613d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
2614d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2615d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
2617d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
26187976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
26197976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
26207976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
26217976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
26227976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
26237976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
2624d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
26251237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
26265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2627d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2628d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
2629d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2630ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2631ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
26321237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
26331237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
26341237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
26351237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
26377976932a1c256d447316ffac58e9821417725e34Eli Friedman
263844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
263944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
264044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
26417976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
26427976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
264327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
26447976932a1c256d447316ffac58e9821417725e34Eli Friedman
26457976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
26467976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
26477976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
26487976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
26497976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
26507976932a1c256d447316ffac58e9821417725e34Eli Friedman
26515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
265244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
26535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
265444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
26555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
265644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
265744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
265844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
265944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
26601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
266144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
266244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
26631237c673c07f9d827129ba02720108816abde562Ted Kremenek
2664d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
2665d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2666d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2667d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
26681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
2669d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2670d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
26711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26721237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
26731237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
26741237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2675d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
2676d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
26772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
26782d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
26792d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
26802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
26812d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
26822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
26832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
26842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
26852d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
26862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
26872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
26892333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
26902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
269144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
269244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
269344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
26942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
26952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
269644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
26972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
26982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
26992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
27002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
27032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
27072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
27082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
27092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
27102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
271174626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg.
27127c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
27135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
27147c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
27157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
27167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
27172333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(VAArgExprClass, t, t->isDependentType(), false),
27187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
27197c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
27207c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
272274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  /// \brief Create an empty __builtin_va_arg expression.
2723d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2724d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
27255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
27265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
2727d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
2728d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2729d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2730d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
27311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2732d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2733d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2734d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
27357c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
27367c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
27371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
27387c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
27397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
27407c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
27417c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
27421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
27447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
27451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
27467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
27494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
27504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
27514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
27524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
27534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
27544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
27554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
27564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
2757196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
27584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
27594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
27604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
27614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
27624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
27634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
27644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
27654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
2766196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
27674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
27684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
27694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
27704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
27714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
27724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
27734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
27743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
27754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
27764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
27774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
2778196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
27794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
27804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
27814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
27824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
27834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
27844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
278566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
2786ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // FIXME: Eliminate this vector in favor of ASTContext allocation
2787709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef ASTVector<Stmt *> InitExprsTy;
2788709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprsTy InitExprs;
278966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
27924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
27934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
27944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27950bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
27960bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
27970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
27980bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2799a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
2800a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
2801a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
2802a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
280366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
2804709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2805709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek               Expr **initexprs, unsigned numinits,
2806ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek               SourceLocation rbraceloc);
2807d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2808d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
2809709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2810709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : Expr(InitListExprClass, Empty), InitExprs(C) { }
28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2812ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  unsigned getNumInits() const { return InitExprs.size(); }
28131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getInit(unsigned Init) const {
2815c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
28164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
281766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
28181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getInit(unsigned Init) {
2820c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
28214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
282266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
2825c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
28269e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
28279e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
2828c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
2829fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
2830709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  void reserveInits(ASTContext &C, unsigned NumInits);
28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
28334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
28344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
28354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
28364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
28374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
28384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
28394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
28414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
28424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
28434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
28444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
28454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
28464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
2847709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
2848c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
28490bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
28500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
28510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
28520bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
28530bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
28540bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
28550bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
28560bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
28570bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2858c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
2859c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2860b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
2861b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
2862b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
28631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2864d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2865d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2866d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
286787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
286887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
28694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
28704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
28714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
28721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
28734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
28744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
28754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2876a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
28771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
2878d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
2879a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
2880a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
288166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
288266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
28831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
288466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
288666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
288766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
28881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
288966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
289066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
289166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2893709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::iterator iterator;
2894709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::reverse_iterator reverse_iterator;
28951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2896ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator begin() { return InitExprs.begin(); }
2897ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator end() { return InitExprs.end(); }
2898ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
2899ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
290066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
290166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
290205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
290305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
290405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
290505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
290605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
290705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
290805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
291005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
291105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
291205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
291305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
291405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
291505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
291605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
291705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
291805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
291905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
292005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
292105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
292205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2923ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2924ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2925ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2926ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2927ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
292805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
292905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
293005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
293105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2932eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
293305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2934eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
293505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
293605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
293705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
293805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2939ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2940ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2941ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2942ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
294305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
294405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
294505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
294605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
294705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2948ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2949319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
2950ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2951eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
29529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
29539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
295405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2955d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2956d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2957d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2958d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
295942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
29601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
296142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
2962319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void DestroyDesignators(ASTContext &C);
2963c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
296405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
296505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
296605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
296705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
296805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
296905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
297005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
297105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
297205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
297305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
29741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
297505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
297605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
29771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
297805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
297905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
298005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
298105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
298205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
298305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
298405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
298505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
298605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
298705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
298805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
298905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
299005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
299105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
299205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
299405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
299505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
299605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
299705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
299805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
299905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
300005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
300105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
300205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
300305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
300405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
300505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
300605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
300705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
300805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
300905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
301005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
301105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
301205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
301305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
301405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
301505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
301605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
301705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
301805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
3019ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
3020ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
302105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
30221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
30231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
302405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
302505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
302605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
302705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
302805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
302905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
303005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
30311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
303205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
303305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
303405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
303505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
303605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
303705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
303905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
304005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
30411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
304205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
305905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
306005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
306405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
306505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
306705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
306805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
306987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
307087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
307187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
307287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
307387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
307405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
307505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
307605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
307705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
307805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
307905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
308005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
308105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
308505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
308805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
308905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
309005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
309505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
30964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3097d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
3098d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3099d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
3100d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
3101d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
3102d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
31034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
31044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
31054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
31064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
31074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
31084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
31111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
3115eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3117d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3118d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
311905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
312005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
312105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
3124ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
31261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
3127ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
312805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3129711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3130711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3131c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void setDesignators(ASTContext &C, const Designator *Desigs,
3132319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                      unsigned NumDesigs);
3133d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
313505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
313605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
313705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3141d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
3144eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
3145eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
3146d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
314705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
314805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
31491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
315005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
315105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
315205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
315305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
315405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
315505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
315605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3157d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
3158d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
3159d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
3160d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
3161d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
3162d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3163d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
3164d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3165d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3166d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3167d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3168d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3169d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3170d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
3171d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3172d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3173d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3174d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3175d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3176d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3177ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
3178ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
3179319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3180ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
3181ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
31851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
31911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
31923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
31933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
31953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
31963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
31971a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
31981a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
31993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
32001a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
32011a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
32033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
32052333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
32063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
3207d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
3208d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
3209d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
3210d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
32111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
32133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
32143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
32153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
32173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
32183498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
32193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
32213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
32221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
322405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
32252ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
32272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
32282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
32292ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
32302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected:
32322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual void DoDestroy(ASTContext& C);
32331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
32362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                unsigned numexprs, SourceLocation rparenloc);
32372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  ~ParenListExpr() {}
32392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
324137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
32421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
32462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
32472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
32482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
32491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
32512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
32522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
32532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
32542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
325583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
32582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
32592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual SourceRange getSourceRange() const {
32612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
32621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
32632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
32641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
32652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
32662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
32692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_begin();
32702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_end();
327137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis
327237bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  friend class PCHStmtReader;
327337bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  friend class PCHStmtWriter;
32742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
32752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
32784eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
32794eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
32804eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
3281a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3282a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
3283a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
3284a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3285a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
328673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
328773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
328873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
3289a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
3290a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
3291d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
3292a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
3293a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
3294a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
3295a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
32962333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
32972333f7727f97018d6742e1e0938133bcfad967abEli Friedman           base->isValueDependent()),
3298d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
32991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3300d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
3301d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
3302d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
3303d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3304a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
3305a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
3306d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
3307d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3308d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
3309d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3310d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3311d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3312d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3313d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3314a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
3315a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
33161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3317a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
3318a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
3319a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
33201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3321a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3322a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
3323a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
33241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3325a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
3326a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3327a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
33281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33292140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
33302140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
33312140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
3335a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3336a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
33371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3338a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
3339a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
3340a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
3341a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
3342a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3343a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
334456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
33459c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
33464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
334756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
334856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
3349b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
33504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3351b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
33522333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
3353b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
33549c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
335584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
335684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
335784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
3358d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
335956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
336084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
336184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
336256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
336356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
336456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
336556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
33669c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
33679c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
336856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
33699c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
33709c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
337156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
337256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
337356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
3374b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
33755b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
3376b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
337784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3378b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33809c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
33814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
33824eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
33831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
33854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
33864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
33874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
33904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
33914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
33921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ValueDecl *D;
33934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
33947d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool IsByRef : 1;
33957d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool ConstQualAdded : 1;
339689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  Stmt *CopyConstructorVal;
33974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
33982333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Fix type/value dependence!
33991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
340089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian                   bool constAdded = false,
340189f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian                   Stmt *copyConstructorVal = 0)
34022333f7727f97018d6742e1e0938133bcfad967abEli Friedman  : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
340389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    ConstQualAdded(constAdded),  CopyConstructorVal(copyConstructorVal) {}
340494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
340594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
340694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
340794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
340894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
34091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
34114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
341294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
341394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
341494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
341594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
341694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
34174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
34181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
342094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
34211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34227d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool isConstQualAdded() const { return ConstQualAdded; }
34237d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setConstQualAdded(bool C) { ConstQualAdded = C; }
342489f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian
342589f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  const Expr *getCopyConstructorExpr() const
342689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    { return cast_or_null<Expr>(CopyConstructorVal); }
342789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  Expr *getCopyConstructorExpr()
342889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    { return cast_or_null<Expr>(CopyConstructorVal); }
342989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; }
343094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
34311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
34321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BlockDeclRefExprClass;
34334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
34344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
34351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
34374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
34384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
34394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
34404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
34415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
34425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
34435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3444