Expr.h revision 9a901bb63990574ff0bcc12ff851d7a71cff8ddb
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
21525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
223b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
23c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
26590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
27c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
28c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
29c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
318e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
3488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
3588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
3688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
43898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
44898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// TypeDependent - Whether this expression is type-dependent
45898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
46898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// ValueDependent - Whether this expression is value-dependent
49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
50898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor should go away and we should
54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // require every subclass to provide type/value-dependence
55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // information.
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T)
57b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
5883233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor    setType(T);
5983233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor  }
60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
62b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
660b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
69f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregorpublic:
70f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
71f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  void setType(QualType t) {
729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
79f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor    assert((TR.isNull() || !TR->isReferenceType()) &&
808320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
81f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
82f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor    TR = t;
839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
8477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
85898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
86898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
87898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent.
89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValueDependent(bool VD) { ValueDependent = VD; }
960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<typename T>
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1100b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setTypeDependent(bool TD) { TypeDependent = TD; }
1120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
122026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
123026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
124026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
125026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner                              SourceRange &R2) const;
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
13808ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
13976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
145fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
14686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
14786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_MemberFunction
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
14928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and if it is a structure or union, does not have any member (including,
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
15644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
15744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
15844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
15944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
164fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
166ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1694f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1705daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
171ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
17286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
17386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_MemberFunction
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
17544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
17644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  bool isBitField();
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
184590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
185590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
187590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
1888070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
189590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
191c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
192c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
193c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  bool isConstantInitializer(ASTContext &Ctx) const;
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
19694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
1972d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
19894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
19994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
20094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
20194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
20294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
20394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
20594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
20694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
21894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2196ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
220019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
221019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
222019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2235b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2245b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
2256ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
22645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
22745b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
228c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
22951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
23051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
23151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
23251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
2331b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue.
2341b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2351b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
236efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
237efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
238efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
239efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool isNullPointerConstant(ASTContext &Ctx) const;
240efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
2412e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  /// hasGlobalStorage - Return true if this expression has static storage
2424cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// duration.  This means that the address of this expression is a link-time
2434cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// constant.
2442e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  bool hasGlobalStorage() const;
24544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian
24644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
24744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// write barrier.
24844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  bool isOBJCGCCandidate() const;
2494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
2504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
2514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  its subexpression.  If that subexpression is also a ParenExpr,
2524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
2534e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
2544e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* IgnoreParens();
25556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
25656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
25727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
25856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
2594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
260ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
261ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
262ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
263ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
264ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
2654e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  const Expr* IgnoreParens() const {
2664e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
2674e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
26856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
26956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
27056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
271ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
272ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
273ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
274ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
275898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
276898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
277898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getStmtClass() <= lastExprConstant;
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
2938e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *D;
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
2959e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
2969e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
2971a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // FIXME: Eventually, this constructor will go away and all subclasses
2981a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // will have to provide the type- and value-dependent flags.
2998e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
3009e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    Expr(SC, t), D(d), Loc(l) {}
3019e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3021a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
3031a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor              bool VD) :
3041a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor    Expr(SC, t, TD, VD), D(d), Loc(l) {}
3051a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor will go away and all clients
308898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // will have to provide the type- and value-dependent flags.
3098e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
312898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty declaration reference expression.
3160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit DeclRefExpr(EmptyShell Empty)
3170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
3180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
3198e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *getDecl() { return D; }
3208e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  const NamedDecl *getDecl() const { return D; }
321904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  void setDecl(NamedDecl *NewD) { D = NewD; }
322904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
3239e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
3240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
3289e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return T->getStmtClass() == DeclRefExprClass ||
3291a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == CXXConditionDeclExprClass ||
3301a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == QualifiedDeclRefExprClass;
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
33377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
33477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
33577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
33677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
339d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
340d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
341227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
342227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
343227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
344227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
345cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor    PrettyFunction
346227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
347227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
348227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
349227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
350227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
351227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
352d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
353d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
354227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
35517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
35617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  explicit PredefinedExpr(EmptyShell Empty)
35717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
35817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
359227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
36017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
36117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
36217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
36317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
36417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
365b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // FIXME: The logic for computing the value of a predefined expr should go
366b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // into a method here that takes the inner-most code decl (a block, function
367b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // or objc method) that the expr lives in.  This would allow sema and codegen
368b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // to be consistent for things like sizeof(__func__) etc.
369b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner
370227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
371227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
372227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  static bool classof(const Stmt *T) {
373d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    return T->getStmtClass() == PredefinedExprClass;
374227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
375d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
37677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
37777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
37877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
37977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
380227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
381227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
392a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
3930b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
3940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit IntegerLiteral(EmptyShell Empty)
3950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
3960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
397a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  IntegerLiteral* Clone(ASTContext &C) const;
398a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
402313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
403313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
404313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
4050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
4060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == IntegerLiteralClass;
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
41277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
41377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
41477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
41577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
421c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
424c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
425c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4280b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
4290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
4300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4312eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  SourceLocation getLoc() const { return Loc; }
432c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
4332eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
4400b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
4410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == CharacterLiteralClass;
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
44677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
44777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
44877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
44977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
453525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
454720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
457720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
458720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
459720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
46117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
46217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  FloatingLiteral(EmptyShell Empty)
46317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
46417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
465c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
46617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
46717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
468720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
46917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
470c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
471da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
472da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
473da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
474da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
475da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
47617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
47717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
47817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
4794863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // FIXME: The logic for computing the value of a predefined expr should go
4804863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // into a method here that takes the inner-most code decl (a block, function
4814863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // or objc method) that the expr lives in.  This would allow sema and codegen
4824863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // to be consistent for things like sizeof(__func__) etc.
4834863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == FloatingLiteralClass;
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
49077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
49177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
49277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
49377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
4975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
4985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
4995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
5005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
5015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
5025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
5035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
5045d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
5055d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
5065d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
507cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
508cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ImaginaryLiteral(EmptyShell Empty)
509cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
510cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
5125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
513cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
514cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
5165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const Stmt *T) {
5175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return T->getStmtClass() == ImaginaryLiteralClass;
5185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
5195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
5205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
5215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
5225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
5235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
5245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
5255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
526e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
527e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
528e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
529a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
530c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
531c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
532690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
533690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
5348bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
535690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
536c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
537c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
538c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
539c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
540c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
541c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
546726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
547726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
5482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
5522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
5532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
555a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
5562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
5582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
5602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
5612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
5622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
563a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
564673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
565673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
566673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
567a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  StringLiteral* Clone(ASTContext &C) const;
568726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  void Destroy(ASTContext &C);
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
572673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
573673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
574673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setStrData(ASTContext &C, const char *Str, unsigned Len);
575673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
577673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
578673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
5798d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
58033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    for (unsigned i = 0; i < getByteLength(); ++i)
5818d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff      if (!isascii(getStrData()[i]) || !getStrData()[i])
58233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
58333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
58433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
585726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
586726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
587726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
588726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
589726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
590726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
591726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
592726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
593673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
594673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
595673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
596673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
597673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
598b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
599b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
600b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
603726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == StringLiteralClass;
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
60977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
61077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
61177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
61277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
6195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
622898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
623898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           val->isTypeDependent(), val->isValueDependent()),
624898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
626c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
627c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  explicit ParenExpr(EmptyShell Empty)
628c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
629c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
6305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
6315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
632c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
633c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
634866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
636313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
637313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
638c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
639313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
640313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
641313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
642c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
643313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ParenExprClass;
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
64877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
64977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
65077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
65177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
6560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
658dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
659dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
660dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
661dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
662dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
663dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
664dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
66573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
66673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   subexpression is a compound literal with the various MemberExpr and
66773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   ArraySubscriptExpr's applied to it.
66873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
67113d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
67973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
68073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
6835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
6899103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
6909103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
6919103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isValueDependent()),
6929103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6940b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
6950b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit UnaryOperator(EmptyShell Empty)
6960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
6970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
6990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
7000b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
7020b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
7030b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
7060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
7070b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
7092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
7102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
7112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7135a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
7142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
7152085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
7162085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7175a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
7185a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
7205d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
7225a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
729bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
730bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
731bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
732bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
733bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
734bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
735bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
736bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == UnaryOperatorClass;
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
74977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
75077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
75177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
75277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
7560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
7570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
7580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
7590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
760d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
761d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    void *Ty;
762d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
763d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
766ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, QualType T,
7670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
7680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
7692850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
770ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
7712850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
772ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           T->isDependentType()),
773ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
774ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
775ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
776ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
777ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, Expr *E,
778ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
779ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
780ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
781ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
782ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
783ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
784ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
785ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
786d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
7870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
7880b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
7890b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
7900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
7910b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7929048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar  virtual void Destroy(ASTContext& C);
7939048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
7950b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
7960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
7980518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
7990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
800d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return QualType::getFromOpaquePtr(Argument.Ty);
8010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
802caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
8030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
804d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
8050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
806caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
807caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
808caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
8090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8100b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
8110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(QualType T) {
8120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
8130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    isType = true;
8140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
8150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
8170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
8180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
8190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
8200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
8210518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
82276e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
8230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
8240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
8260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
827866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
828866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
829866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
830866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
8330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return T->getStmtClass() == SizeOfAlignOfExprClass;
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
83677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
83777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
83877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
83977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
84877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
8495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8522324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
85373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
8542850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
8552850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
8562850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
8572850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
85873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
85973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
86073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
862cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
863cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
864cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
865cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8662324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
8672324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
8682324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
8692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
8702324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
87133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
87233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
87333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
87433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
8755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
8765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
877cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
878cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
8805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
881cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
8822324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
88377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getBase() {
8845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
88577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
88677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
8872324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  const Expr *getBase() const {
8885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
8892324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
89177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getIdx() {
8925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
8932324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8942324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
89577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
8965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
89777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
899866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
90077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
902866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
903026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
904cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
905cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
9065cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ArraySubscriptExprClass;
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
91277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
91377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
91477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
91577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
919b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
920b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
921b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
922b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is
923b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
924b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
92677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
9275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
930d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
931d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek  // This version of the ctor is for deserialization.
932b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
933d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek           SourceLocation rparenloc)
934b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  : Expr(SC,t), SubExprs(subexprs),
935d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek    NumArgs(numargs), RParenLoc(rparenloc) {}
936b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
937b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
938b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
939668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
940668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
941d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
943668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
945668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
9461f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
9471f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  CallExpr(ASTContext &C, EmptyShell Empty);
9481f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
949668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
950668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
951668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  void Destroy(ASTContext& C);
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
9545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
95518b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
970668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
971934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
972934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
973934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
974934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
975934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
976d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
977d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
978d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
979d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
9808189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
981d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
9835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
9845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
985d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
986d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
9875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
9885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
989d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
994cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
995cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
9963c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
997cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
998d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
9991f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1000866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1001866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
100277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
1006b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    return T->getStmtClass() == CallExprClass ||
100788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXOperatorCallExprClass ||
100888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXMemberCallExprClass;
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
101188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
101288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
101388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
101477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
101577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
101677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1019ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
1022ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1023ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
10245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
1025ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1026ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1027ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
102886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *MemberDecl;
1029ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1030ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
1032ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1033ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
1034ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  bool IsArrow;
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
103686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
1037510190777c4bd53e960eea4665b204778fec1b64Eli Friedman             QualType ty)
1038510190777c4bd53e960eea4665b204778fec1b64Eli Friedman    : Expr(MemberExprClass, ty),
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
1040510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
10411f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty member reference expression.
10421f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  explicit MemberExpr(EmptyShell Empty) : Expr(MemberExprClass, Empty) { }
10431f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
104488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
10455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
104657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
104757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
104857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
104957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
105057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
105186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *getMemberDecl() const { return MemberDecl; }
105288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
10531f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
10551f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
10561f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1057ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1058ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1059026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
10601f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getBase()->getLocStart(), MemberLoc);
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1065866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == MemberExprClass;
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
10721237c673c07f9d827129ba02720108816abde562Ted Kremenek
10731237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
10741237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
10751237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1078aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5]
1079aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1080aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
10810fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
10820fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
10830fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
10840fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
10855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1086e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1087aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
1088a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1089a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                      bool fileScope)
1090a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1091a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner      FileScope(fileScope) {}
1092aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
1093ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1094ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1095ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1096ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
10975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
10985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1099ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1100e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1101e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1102ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1103ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
11040fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1105ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1106ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
110773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
11080fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
11090fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
11100fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
11110fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
111273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
11130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
111473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1115aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
1116aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const Stmt *T) {
1117aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    return T->getStmtClass() == CompoundLiteralExprClass;
1118aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1119aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
11201237c673c07f9d827129ba02720108816abde562Ted Kremenek
11211237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
11221237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
11231237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1124aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1125aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
112649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
112749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
112849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
112949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
11300835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
11310835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
11320835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
11330835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1134898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1135898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1136898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1137898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1138898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1139898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
1140898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent())),
1141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Op(op) {}
11420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
1143087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
1144087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  CastExpr(StmtClass SC, EmptyShell Empty)
1145087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
1146087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
11470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
11480835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
11490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1150087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
1151087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
11520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const Stmt *T) {
11539d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
11549d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
11559d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
11569d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
11576eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
11580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis      return true;
11599d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
11609d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
11610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
11620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
11630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
11640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
11650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
11660835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
11670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
11680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
116949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
117049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
117149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
117249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
117349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1174bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1175bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1176bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1177bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1178bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1179bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1180bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
1181bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) {
1182bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1183bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1184bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
11850835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1186eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1187eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1188eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
118949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1190eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1191b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
119290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1193087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
1194087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  explicit ImplicitCastExpr(EmptyShell Shell)
1195087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
1196087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
1197087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
11980835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
11990835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
12000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
120190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1202eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1203eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1204eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1205eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1206eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1207eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
120849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const Stmt *T) {
120949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff    return T->getStmtClass() == ImplicitCastExprClass;
121049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
121149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
121249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
121349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
121449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
121549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code.
121649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
121749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
121849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
121949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
122049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
122149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
122349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
122449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
122549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
122649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
122749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
122849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
122949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
12300835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
123149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// TypeAsWritten - The type that this expression is casting to, as
123249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// written in the source code.
123349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType TypeAsWritten;
123449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
123549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
12368320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
12378320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
123849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
1239db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
1240db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1241db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
1242db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
124349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
124449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
124549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
124649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType getTypeAsWritten() const { return TypeAsWritten; }
1247db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
124849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
124949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
12509d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
12516eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
12529d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
12539d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
125449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
12559d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
12569d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
125749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
125849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
125949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
126049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
12616eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
126249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
126349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
12646eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
1265b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
1266b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12686eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1269b2f9e516327310d95840d442416084508f80c183Steve Naroff                    SourceLocation l, SourceLocation r) :
1270b2f9e516327310d95840d442416084508f80c183Steve Naroff    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1271b2f9e516327310d95840d442416084508f80c183Steve Naroff    LPLoc(l), RPLoc(r) {}
127249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
1273db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
1274db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  explicit CStyleCastExpr(EmptyShell Shell)
1275db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1276db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1277b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
1278db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1279db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1280b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
1281db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1282db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
1284b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
12876eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    return T->getStmtClass() == CStyleCastExprClass;
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12896eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
12933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
12943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
12953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
12963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
12973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
12983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
12993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
13003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
13013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
13023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
13033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
13043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
13053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
13063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
13073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
13083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
13093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
131403d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
1315224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
133417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
133517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
13365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
133717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
133817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
133917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic:
13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
134117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
134217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
1343898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
1344898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
1345898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent()),
1346898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
13471237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
13481237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isCompoundAssignmentOp() &&
13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1353db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
1354db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  explicit BinaryOperator(EmptyShell Empty)
1355db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1356db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
135717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
1358db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1359db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
1361db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
1362db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1364db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
13655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1366db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1367db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1376063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
1377063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
1378063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1379063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
1380063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1381063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
1382063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1383063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1389f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1390f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1391f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
1392f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1393f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1394f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
1395f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1396f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1397f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
1398f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1403eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  static bool classof(const Stmt *S) {
1404eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == BinaryOperatorClass ||
1405eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner           S->getStmtClass() == CompoundAssignOperatorClass;
14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
14081237c673c07f9d827129ba02720108816abde562Ted Kremenek
14091237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
14101237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
14111237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
14121237c673c07f9d827129ba02720108816abde562Ted Kremenek
14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
141417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
141517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation oploc, bool dead)
141617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
14171237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
14181237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1420ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1421ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  BinaryOperator(StmtClass SC, EmptyShell Empty)
1422ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
1432ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
1433ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1436ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
1437ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
143817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
143917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1440ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
1441ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isCompoundAssignmentOp() &&
14435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1446ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
1447ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
1448ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
1449ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1450ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
1451ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
1452ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1453ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
1454ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
1455ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1456ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
1457ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
1458ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *S) {
1461eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == CompoundAssignOperatorClass;
14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
14691237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
14705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1473898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
1474898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
1475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
1476898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
1477898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1478898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           (cond->isValueDependent() ||
1479898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
1480898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (rhs && rhs->isValueDependent()))) {
14811237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
14821237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
14831237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
14841237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1486ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
1487ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
1488ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
1489ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1490395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
1491395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
14925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1493ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
1494395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1495395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1496395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
1497395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
1498395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
1499395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1500395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  is only evaluated once.
1501395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
15025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1503395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
1504395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1505395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1506395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
15075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1508395a2abf0028968d85958610e393e067885dc14fTed Kremenek
15095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1510ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1511ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
15125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1513ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ConditionalOperatorClass;
15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
15221237c673c07f9d827129ba02720108816abde562Ted Kremenek
15231237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15241237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15251237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
15296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
15305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
15315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15336481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
15346481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
15356481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15377d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
15387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  explicit AddrLabelExpr(EmptyShell Empty)
15397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
15407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
15427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
15437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
15447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
15457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
15517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
15527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
15546481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    return T->getStmtClass() == AddrLabelExprClass;
15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15566481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
15571237c673c07f9d827129ba02720108816abde562Ted Kremenek
15581237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15591237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15601237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
15615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1562ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1563ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1564ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1565ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
1566ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
15675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
1568ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
1569ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
1570d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
1571d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
1572d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1573ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
15746a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
15756a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
15766a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
15775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
15785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
15796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
15806a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
1581ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
1582ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
1583ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1585026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
15866a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1587026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
15886a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1589026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
1590ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
1591ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return T->getStmtClass() == StmtExprClass;
1592ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
1593ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
15941237c673c07f9d827129ba02720108816abde562Ted Kremenek
15951237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15961237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15971237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1598ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
1599ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1600d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1601d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
1602d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
1603d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
1604d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
1605d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
1606d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
1607363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1608d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
1609363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1610d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff                      QualType t1, QualType t2, SourceLocation RP) :
1611d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1612363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    BuiltinLoc(BLoc), RParenLoc(RP) {}
1613d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
161444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
161544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
161644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
161744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
16187f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
161944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
16207f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
162144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
1622ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
162344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
162444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
162544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
162644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
162744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
162844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
1629d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
1630363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1631d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1632d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
1633d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    return T->getStmtClass() == TypesCompatibleExprClass;
1634d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1635d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
16361237c673c07f9d827129ba02720108816abde562Ted Kremenek
16371237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16381237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16391237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1640d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
1641d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
1642d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
1643d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
1644d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
1645d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
1646d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
1647d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
1648d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
1649d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
1650d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1651d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
1652d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
1653d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
1654d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
16555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
1656d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
1657d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1658d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
1659d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1660d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    QualType Type, SourceLocation BLoc,
1661d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    SourceLocation RP) :
1662d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1663f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek    RParenLoc(RP), NumExprs(nexpr) {
1664f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek
16655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    SubExprs = new Stmt*[nexpr];
1666d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
1667d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
1668d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
166994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
167094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
167194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit ShuffleVectorExpr(EmptyShell Empty)
167294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
167394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
167494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
167594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
167694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
167794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
167894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
167994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1680d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
1681d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
1682d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1683d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
1684d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return T->getStmtClass() == ShuffleVectorExprClass;
1685d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1686d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
1687d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1688d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ~ShuffleVectorExpr() {
1689d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    delete [] SubExprs;
1690d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1691d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1692d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1693d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
1694d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
1695d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
1696d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1697d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
1698d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
1699d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
17005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1701d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1702d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
1703d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
17045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
170794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setExprs(Expr ** Exprs, unsigned NumExprs);
170894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1709dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1710dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
17119a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
1712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1714d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
1715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
1716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
1717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
1718d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1719d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1720d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with
1721d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
17227976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
17237976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
17247976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
17257976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
17267976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
17277976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
1728d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
17291237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
17305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1731d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1732d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
1733d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1734d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff             SourceLocation RP)
1735d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : Expr(ChooseExprClass, t),
17361237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
17371237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
17381237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
17391237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
17401237c673c07f9d827129ba02720108816abde562Ted Kremenek    }
17417976932a1c256d447316ffac58e9821417725e34Eli Friedman
174244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
174344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
174444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
17457976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
17467976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
174727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
17487976932a1c256d447316ffac58e9821417725e34Eli Friedman
17497976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
17507976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
17517976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
17527976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
17537976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
17547976932a1c256d447316ffac58e9821417725e34Eli Friedman
17555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
175644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
17575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
175844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
17595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
176044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
176144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
176244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
176344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
176444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
176544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
176644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
17671237c673c07f9d827129ba02720108816abde562Ted Kremenek
1768d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
1769d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1770d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1771d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
1772d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return T->getStmtClass() == ChooseExprClass;
1773d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1774d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
17751237c673c07f9d827129ba02720108816abde562Ted Kremenek
17761237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17771237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17781237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1779d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
1780d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
17812d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
17822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
17832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
17842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
17852d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
17862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
17872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
17882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
17892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
17902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
17912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
17922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  GNUNullExpr(QualType Ty, SourceLocation Loc)
17932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
17942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
179544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
179644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
179744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
17982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
17992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
180044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
18012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
18032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
18042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
18052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
18062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return T->getStmtClass() == GNUNullExprClass;
18072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
18082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
18092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
18112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
18122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
18132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
18142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start.
18167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
18175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
18187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
18197c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
18207c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
18217c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : Expr(VAArgExprClass, t),
18227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
18237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
18247c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
18257c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
1826d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Create an empty __builtin_va_start expression.
1827d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
1828d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
18295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
18305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1831d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1832d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
1833d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1834d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1835d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
1836d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1837d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1838d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
18397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
18407c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
18417c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
18427c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
18437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
18447c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
18457c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
18467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
18477c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
18487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
18497c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_end();
18507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
18517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
18524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
18534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
18544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
18554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
18564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
18574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
18584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
18594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
18604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
1861196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
18634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
18644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
18654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
18664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
18674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
18684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
18694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
1870196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
18724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
18734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
18744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
18754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
18764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
18774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
18783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
18794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
18804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
18814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
1882196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
18844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
18854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
18864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
18874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
18884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
188966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
18905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  std::vector<Stmt *> InitExprs;
189166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
1892418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner
18934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
18944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
18954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
18964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
18970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
18980bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
18990bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
19000bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1901a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
1902a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
1903a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
1904a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
190566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
190666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
19074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor               SourceLocation rbraceloc);
1908d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
1909d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
1910d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
191166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
1912c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  unsigned getNumInits() const { return InitExprs.size(); }
191366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
191466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  const Expr* getInit(unsigned Init) const {
1915c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
191766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
191866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
191966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  Expr* getInit(unsigned Init) {
1920c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
192266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
192366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
19249e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  void setInit(unsigned Init, Expr *expr) {
1925c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19269e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
19279e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
1928c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
1929fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
1930fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  void reserveInits(unsigned NumInits);
1931fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
19324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
19334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
19354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
19364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
19374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
19384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
19394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
19404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
19414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
19424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
19434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
19454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
19464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
19474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *updateInit(unsigned Init, Expr *expr);
1948c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
19490bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
19500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
19510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
19520bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
19530bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
19540bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
19550bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
19560bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
19570bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1958c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
1959c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1960b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
1961b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
1962b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
19639e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff
1964d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
1965d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
1966d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
196787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
196887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
19694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
19704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
19714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
19744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
19754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1976a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
1977d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void sawArrayRangeDesignator(bool ARD = true) {
1978d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
1979a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
1980a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
198166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
198266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
198366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
198466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
198566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return T->getStmtClass() == InitListExprClass;
198666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
198766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
198866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
198966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
199066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
199166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
19926336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek
19937fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::iterator iterator;
19947fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
19957fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek
19967fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator begin() { return InitExprs.begin(); }
19977fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator end() { return InitExprs.end(); }
19987fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
19997fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
200066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
200166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
200205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
200305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
200405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
200505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
200605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
200705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
200805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
200905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
202205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2023ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2024ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2025ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2026ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2027ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
202905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
203005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
203105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2032eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
203305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2034eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2039ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2040ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2041ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2042ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
204605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
204705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2048ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
204905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
2050ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2051eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
2052ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     unsigned NumSubExprs);
205305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2054d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2055d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2056d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2057d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
205805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
205905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
206005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
206105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
206205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
206305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
206405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
206505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
206605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
206705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
206805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
206905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
207005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
207105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
207305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
207405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
207505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
207705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
207805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
207905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
208005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
208105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
208205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
208305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
208405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
208505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
208605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
208705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned RBracketLoc;
208805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
208905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
209005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
209105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
209205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
209305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
209405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
209505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
209605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
209705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
209805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
209905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
210005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
210105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
210205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
210305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
210405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
210505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
210605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
210705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
210805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
210905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
211005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
211105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
211205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
2113ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
2114ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
211505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
211605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
211705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation FieldLoc)
211805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
211905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
212005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
212105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
212205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
212305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
212405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
212505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
212605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
212705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
212805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
212905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
213005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
213105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
213205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
213305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
213405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
213505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
213605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
213705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
213805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
213905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
214005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
214105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
214205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
214305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
214405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
214505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
214605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
214705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
214805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
214905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
215005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
215105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
215205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
215305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
215405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
215505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
215605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
215705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
215805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
215905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
216005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
216105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
216205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
216387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
216487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
216587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
216687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
216787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
216805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
216905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
217005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
217105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
217205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
217305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
217405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
217505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
217605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
217705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
217805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
217905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
218005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
218105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
218205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
218305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
218405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
218505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
218605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
218705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
218805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
218905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
21904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2191d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
2192d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2193d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
2194d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
2195d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
2196d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
21974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
21984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
21994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
22004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
22014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
22024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
220305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
220405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
220505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
220605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
220705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
220805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
2209eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
221005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2211d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
2212d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
221305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
221405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
221505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
221605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
221705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
2218ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
2219ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_end() {
2220ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return Designators + NumDesignators;
2221ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
222205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2223711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2224711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
2225d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setDesignators(const Designator *Desigs, unsigned NumDesigs);
2226d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
222705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
222805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
222905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
223005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
223105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
223205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
223305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2234d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
223505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
223605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
2237eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
2238eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
2239d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
224005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
224105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
224205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getInit() const {
224305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
224405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
224505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
224605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
224705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
224805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
224905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2250d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
2251d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
2252d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
2253d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
2254d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
2255d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2256d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
2257d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
2258d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2259d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
2260d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
2261d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2262d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2263d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
2264d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
2265d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2266d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
2267d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
2268d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2269d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2270ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
2271ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
2272ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  void ExpandDesignator(unsigned Idx, const Designator *First,
2273ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
2274ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
227505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
227605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2277ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  virtual void Destroy(ASTContext &C);
2278ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
227905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
228005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == DesignatedInitExprClass;
228105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
228205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
228305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
228405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
228505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
22863498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_end();
22873498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
22883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
22893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
22903498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
22913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
22921a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
22931a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
22943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
22951a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
22961a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
22973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr {
22983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
22993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  explicit ImplicitValueInitExpr(QualType ty)
23003498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    : Expr(ImplicitValueInitExprClass, ty) { }
23013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
2302d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
2303d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
2304d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
2305d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
23063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const Stmt *T) {
23073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
23083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
23093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
23103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
23113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
23123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
23133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
23143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
23153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
23163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
231705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_end();
231805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
231905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
23204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
23214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
23224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
23234eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
2324a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2325a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
2326a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
2327a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2328a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
232973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
233073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
233173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
2332a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
2333a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
2334d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
2335a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
2336a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
2337a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2338a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
2339a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(ExtVectorElementExprClass, ty),
2340d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
2341a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2342d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
2343d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
2344d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
2345d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2346a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
2347a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
2348d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
2349d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2350d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
2351d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
2352d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2353d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
2354d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
2355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2356a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
2357a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
2358a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2359a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
2360a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
2361a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
2362a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2363a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2364a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
2365a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2366a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2367a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
2368a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2369a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2370a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
23712140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
23722140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
23732140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
23742140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
2375a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const Stmt *T) {
2376a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return T->getStmtClass() == ExtVectorElementExprClass;
2377a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2378a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
2379a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2380a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
2381a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
2382a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
2383a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
2384a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2385a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
238656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
23879c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
23884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
238956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
239056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
2391b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
23924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
2393b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2394b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump    : Expr(BlockExprClass, ty),
2395b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
23969c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
239784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
239884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
239984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
2400d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
240156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
240284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
240384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
240456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
240556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
240656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
240756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
24089c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
24097297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  const Stmt *getBody(ASTContext &C) const { return getBody(); }
24107297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  Stmt *getBody(ASTContext &C) { return getBody(); }
24117297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor
24129c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
241356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
24149c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
24159c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
241656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
241756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
241856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
2419b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
24205b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
2421b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
242284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
2423b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
24244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
24259c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
24264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
24274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
24284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
24304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
24314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
24324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
24339c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
24344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
24354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
24364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
24374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *D;
24384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
24394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool IsByRef;
24404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
24414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
24424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
244394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
244494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
244594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
244694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
244794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
24484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
24504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
245194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
245294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
245394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
245494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
245594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
24564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
24574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
245994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
246094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
24614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
24624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return T->getStmtClass() == BlockDeclRefExprClass;
24634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
24644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
24654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
24674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
24684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
24694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
24704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
24725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2474