Expr.h revision 33bbbc5ec8269bc2cde5b84f970fa49319a30267
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
17833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
17933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
18033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
186590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
187590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
189590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
1908070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
191590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
193c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
194c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
195c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  bool isConstantInitializer(ASTContext &Ctx) const;
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
19894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
1992d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
20094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
20194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
20294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
20394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
20594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
20694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
21894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
21994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2216ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
222019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
223019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
224019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2255b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2265b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
2276ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
22845b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
22945b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
230c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
23151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
23251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
23351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
23451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
2351b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue.
2361b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2371b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
238efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
239efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
240efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
241efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool isNullPointerConstant(ASTContext &Ctx) const;
242efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
2432e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  /// hasGlobalStorage - Return true if this expression has static storage
2444cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// duration.  This means that the address of this expression is a link-time
2454cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// constant.
2462e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  bool hasGlobalStorage() const;
24744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian
24844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
24944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// write barrier.
25044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  bool isOBJCGCCandidate() const;
2514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
2524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
2534e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  its subexpression.  If that subexpression is also a ParenExpr,
2544e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
2554e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
2564e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* IgnoreParens();
25756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
25856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
25927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
26056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
2614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
262ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
263ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
264ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
265ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
266ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
2674e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  const Expr* IgnoreParens() const {
2684e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
2694e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
27056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
27156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
27256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
273ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
274ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
275ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
276ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
277898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
278898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
279898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getStmtClass() <= lastExprConstant;
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
2958e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *D;
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
2979e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
2989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
2991a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // FIXME: Eventually, this constructor will go away and all subclasses
3001a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // will have to provide the type- and value-dependent flags.
3018e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
3029e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    Expr(SC, t), D(d), Loc(l) {}
3039e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3041a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
3051a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor              bool VD) :
3061a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor    Expr(SC, t, TD, VD), D(d), Loc(l) {}
3071a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
309898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor will go away and all clients
310898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // will have to provide the type- and value-dependent flags.
3118e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
314898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty declaration reference expression.
3180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit DeclRefExpr(EmptyShell Empty)
3190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
3200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
3218e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *getDecl() { return D; }
3228e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  const NamedDecl *getDecl() const { return D; }
323904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  void setDecl(NamedDecl *NewD) { D = NewD; }
324904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
3259e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
3260b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
3309e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return T->getStmtClass() == DeclRefExprClass ||
3311a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == CXXConditionDeclExprClass ||
3321a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == QualifiedDeclRefExprClass;
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
33577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
33677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
33777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
33877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
341d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
342d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
343227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
344227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
345227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
346227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
347cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor    PrettyFunction
348227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
349227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
350227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
351227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
352227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
353227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
354d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
355d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
356227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
35717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
35817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  explicit PredefinedExpr(EmptyShell Empty)
35917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
36017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
361227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
36217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
36317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
36417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
36517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
36617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
367b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // FIXME: The logic for computing the value of a predefined expr should go
368b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // into a method here that takes the inner-most code decl (a block, function
369b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // or objc method) that the expr lives in.  This would allow sema and codegen
370b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  // to be consistent for things like sizeof(__func__) etc.
371b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner
372227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
373227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
374227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  static bool classof(const Stmt *T) {
375d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    return T->getStmtClass() == PredefinedExprClass;
376227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
377d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
37877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
37977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
38077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
38177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
382227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
383227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
394a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
3950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
3960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit IntegerLiteral(EmptyShell Empty)
3970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
3980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
399a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  IntegerLiteral* Clone(ASTContext &C) const;
400a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
404313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
405313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
406313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
4070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
4080b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4090b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == IntegerLiteralClass;
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
41477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
41577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
41677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
41777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
423c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
426c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
427c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
4310b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
4320b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4332eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  SourceLocation getLoc() const { return Loc; }
434c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
4352eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4400b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
4420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
4430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == CharacterLiteralClass;
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
44877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
44977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
45077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
45177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
455525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
456720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
459720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
460720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
461720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
46317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
46417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  FloatingLiteral(EmptyShell Empty)
46517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
46617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
467c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
46817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
46917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
470720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
47117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
472c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
473da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
474da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
475da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
476da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
477da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
47817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
47917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
48017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
4814863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // FIXME: The logic for computing the value of a predefined expr should go
4824863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // into a method here that takes the inner-most code decl (a block, function
4834863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // or objc method) that the expr lives in.  This would allow sema and codegen
4844863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // to be consistent for things like sizeof(__func__) etc.
4854863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == FloatingLiteralClass;
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
49277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
49377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
49477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
49577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
4995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
5005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
5015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
5025d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
5035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
5045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
5055d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
5065d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
5075d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
5085d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
509cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
510cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ImaginaryLiteral(EmptyShell Empty)
511cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
512cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
5145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
515cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
516cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
5185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const Stmt *T) {
5195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return T->getStmtClass() == ImaginaryLiteralClass;
5205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
5215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
5225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
5235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
5245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
5255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
5265d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
5275d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
528e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
529e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
530e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
531a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
532c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
533c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
534690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
535690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
5368bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
537690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
538c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
539c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
540c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
541c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
542c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
543c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
548726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
549726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
5502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
5542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
5552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
557a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
5582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
5602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
5622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
5632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
5642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
565a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
566673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
567673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
568673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
569a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  StringLiteral* Clone(ASTContext &C) const;
570726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  void Destroy(ASTContext &C);
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
574673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
575673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
576673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setStrData(ASTContext &C, const char *Str, unsigned Len);
577673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
579673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
580673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
5818d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
58233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    for (unsigned i = 0; i < getByteLength(); ++i)
5838d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff      if (!isascii(getStrData()[i]) || !getStrData()[i])
58433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
58533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
58633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
587726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
588726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
589726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
590726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
591726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
592726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
593726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
594726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
595673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
596673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
597673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
598673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
599673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
600b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
601b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
602b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
605726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == StringLiteralClass;
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
61177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
61277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
61377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
61477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
6215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
624898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
625898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           val->isTypeDependent(), val->isValueDependent()),
626898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
628c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
629c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  explicit ParenExpr(EmptyShell Empty)
630c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
631c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
6325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
6335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
634c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
635c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
636866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
638313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
639313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
640c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
641313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
642313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
643313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
644c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
645313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ParenExprClass;
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
65077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
65177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
65277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
65377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
6580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
660dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
661dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
662dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
663dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
664dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
665dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
666dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
66773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
66873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   subexpression is a compound literal with the various MemberExpr and
66973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   ArraySubscriptExpr's applied to it.
67073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
67313d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
68173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
68273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
6855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
6919103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
6929103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
6939103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isValueDependent()),
6949103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
6970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit UnaryOperator(EmptyShell Empty)
6980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
6990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
7010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
7020b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
7040b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
7050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
7080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
7090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
7112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
7122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
7132085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7155a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
7162085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
7172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
7182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7195a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
7205a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
7225d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
7245a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
731bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
732bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
733bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
734bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
735bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
736bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
737bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
738bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == UnaryOperatorClass;
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
75177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
75277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
75377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
75477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
7580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
7590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
7600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
7610518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
762d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
763d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    void *Ty;
764d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
765d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
768ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, QualType T,
7690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
7700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
7712850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
772ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
7732850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
774ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           T->isDependentType()),
775ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
776ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
777ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
778ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
779ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, Expr *E,
780ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
781ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
782ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
783ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
784ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
785ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
786ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
787ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
788d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
7890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
7900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
7910b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
7920b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
7930b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7949048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar  virtual void Destroy(ASTContext& C);
7959048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
7970b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
7980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
8000518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
8010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
802d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return QualType::getFromOpaquePtr(Argument.Ty);
8030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
804caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
8050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
806d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
8070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
808caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
809caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
810caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
8110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
8130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(QualType T) {
8140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
8150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    isType = true;
8160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
8170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
8190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
8200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
8210518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
8220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
8230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
82476e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
8250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
8260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
8280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
829866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
830866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
831866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
832866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
8350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return T->getStmtClass() == SizeOfAlignOfExprClass;
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
83877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
83977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
84077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
84177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
85077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
8515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8542324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
85573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
8562850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
8572850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
8582850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
8592850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
86073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
86173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
86273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
864cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
865cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
866cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
867cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8682324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
8692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
8702324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
8712324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
8722324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
87333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
87433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
87533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
87633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
8775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
8785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
879cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
880cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
8825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
883cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
8842324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
88577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getBase() {
8865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
88777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
88877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
8892324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  const Expr *getBase() const {
8905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
8912324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8922324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
89377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getIdx() {
8945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
8952324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8962324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
89777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
8985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
89977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
901866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
90277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
904866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
905026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
906cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
907cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
9085cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ArraySubscriptExprClass;
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
91477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
91577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
91677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
91777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
921b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
922b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
923b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
924b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is
925b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
926b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
92877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
9295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
932d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
933d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek  // This version of the ctor is for deserialization.
934b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
935d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek           SourceLocation rparenloc)
936b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  : Expr(SC,t), SubExprs(subexprs),
937d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek    NumArgs(numargs), RParenLoc(rparenloc) {}
938b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
939b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
940b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
941668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
942668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
943d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
945668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
947668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
9481f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
9491f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  CallExpr(ASTContext &C, EmptyShell Empty);
9501f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
951668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
952668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
953668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  void Destroy(ASTContext& C);
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
9565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
95718b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
972668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
973934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
974934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
975934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
976934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
977934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
978d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
979d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
980d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
981d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
9828189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
983d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
9855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
9865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
987d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
988d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
9895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
9905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
991d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
996cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
997cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
9983c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
999cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
1000d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
10011f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1002866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1003866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
100477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
1008b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    return T->getStmtClass() == CallExprClass ||
100988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXOperatorCallExprClass ||
101088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXMemberCallExprClass;
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
101388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
101488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
101588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
101677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
101777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
101877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1021ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
1024ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1025ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
10265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
1027ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1028ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1029ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
103086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *MemberDecl;
1031ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1032ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
1034ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1035ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
1036ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  bool IsArrow;
10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
103886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
1039510190777c4bd53e960eea4665b204778fec1b64Eli Friedman             QualType ty)
1040510190777c4bd53e960eea4665b204778fec1b64Eli Friedman    : Expr(MemberExprClass, ty),
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
1042510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
10431f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty member reference expression.
10441f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  explicit MemberExpr(EmptyShell Empty) : Expr(MemberExprClass, Empty) { }
10451f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
104688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
10475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
104857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
104957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
105057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
105157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
105257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
105386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *getMemberDecl() const { return MemberDecl; }
105488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
10551f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
10571f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
10581f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1059ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1060ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1061026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
10621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
106572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
106672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
106772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
106872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
106972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman      return SourceRange(MemberLoc, MemberLoc);
107072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    return SourceRange(BaseLoc, MemberLoc);
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1072866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == MemberExprClass;
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
10791237c673c07f9d827129ba02720108816abde562Ted Kremenek
10801237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
10811237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
10821237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1085aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5]
1086aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1087aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
10880fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
10890fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
10900fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
10910fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
10925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1093e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1094aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
1095a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1096a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                      bool fileScope)
1097a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1098a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner      FileScope(fileScope) {}
1099aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
1100ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1101ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1102ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1103ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
11045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
11055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1106ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1107e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1108e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1109ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1110ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
11110fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1112ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1113ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
111473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
11150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
11160fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
11170fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
11180fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
111973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
11200fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
112173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1122aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
1123aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const Stmt *T) {
1124aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    return T->getStmtClass() == CompoundLiteralExprClass;
1125aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1126aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
11271237c673c07f9d827129ba02720108816abde562Ted Kremenek
11281237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
11291237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
11301237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1131aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1132aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
113349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
113449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
113549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
113649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
11370835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
11380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
11390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
11400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1142898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1143898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1144898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1145898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1146898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
1147898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent())),
1148898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Op(op) {}
11490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
1150087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
1151087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  CastExpr(StmtClass SC, EmptyShell Empty)
1152087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
1153087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
11540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
11550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
11560835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1157087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
1158087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
11590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const Stmt *T) {
11609d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
11619d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
11629d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
11639d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
11646eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
11650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis      return true;
11669d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
11679d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
11680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
11690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
11700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
11710835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
11720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
11730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
11740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
11750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
117649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
117749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
117849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
117949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
118049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1181bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1182bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1183bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1184bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1185bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1186bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1187bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
1188bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) {
1189bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1190bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1191bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
11920835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1193eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1194eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1195eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
119649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1197eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1198b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
119990045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1200087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
1201087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  explicit ImplicitCastExpr(EmptyShell Shell)
1202087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
1203087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
1204087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
12050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
12060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
12070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
120890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1209eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1210eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1211eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1212eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1213eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1214eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
121549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const Stmt *T) {
121649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff    return T->getStmtClass() == ImplicitCastExprClass;
121749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
121849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
121949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
122049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
122149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
122249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code.
122349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
122449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
122549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
122649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
122749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
122849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
123049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
123149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
123249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
123349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
123449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
123549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
123649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
12370835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
123849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// TypeAsWritten - The type that this expression is casting to, as
123949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// written in the source code.
124049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType TypeAsWritten;
124149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
124249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
12438320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
12448320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
124549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
1246db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
1247db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1248db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
1249db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
125049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
125149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
125249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
125349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType getTypeAsWritten() const { return TypeAsWritten; }
1254db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
125549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
125649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
12579d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
12586eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
12599d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
12609d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
126149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
12629d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
12639d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
126449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
126549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
126649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
126749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
12686eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
126949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
127049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
12716eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
1272b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
1273b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12756eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1276b2f9e516327310d95840d442416084508f80c183Steve Naroff                    SourceLocation l, SourceLocation r) :
1277b2f9e516327310d95840d442416084508f80c183Steve Naroff    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1278b2f9e516327310d95840d442416084508f80c183Steve Naroff    LPLoc(l), RPLoc(r) {}
127949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
1280db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
1281db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  explicit CStyleCastExpr(EmptyShell Shell)
1282db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1283db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1284b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
1285db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1286db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1287b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
1288db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1289db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
1291b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
12946eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    return T->getStmtClass() == CStyleCastExprClass;
12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12966eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
13003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
13013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
13023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
13033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
13043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
13053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
13063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
13073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
13083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
13093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
13103fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
13113fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
13123fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
13133fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
13143fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
13153fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
13163fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
132103d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
1322224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
134117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
134217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
13435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
134417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
134517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
134617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic:
13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
134817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
134917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
1350898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
1351898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
1352898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent()),
1353898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
13541237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
13551237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isCompoundAssignmentOp() &&
13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1360db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
1361db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  explicit BinaryOperator(EmptyShell Empty)
1362db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1363db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
136417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
1365db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1366db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
1368db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
1369db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1371db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
13725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1373db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1374db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1383063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
1384063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
1385063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1386063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
1387063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1388063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
1389063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1390063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1396f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1397f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1398f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
1399f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1400f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1401f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
1402f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1403f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1404f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
1405f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1410eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  static bool classof(const Stmt *S) {
1411eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == BinaryOperatorClass ||
1412eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner           S->getStmtClass() == CompoundAssignOperatorClass;
14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
14151237c673c07f9d827129ba02720108816abde562Ted Kremenek
14161237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
14171237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
14181237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
14191237c673c07f9d827129ba02720108816abde562Ted Kremenek
14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
142117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
142217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation oploc, bool dead)
142317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
14241237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
14251237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1427ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1428ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  BinaryOperator(StmtClass SC, EmptyShell Empty)
1429ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
1439ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
1440ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1443ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
1444ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
144517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
144617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1447ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
1448ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isCompoundAssignmentOp() &&
14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1453ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
1454ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
1455ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
1456ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1457ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
1458ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
1459ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1460ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
1461ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
1462ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1463ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
1464ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
1465ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *S) {
1468eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == CompoundAssignOperatorClass;
14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
14761237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
14775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1480898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
1481898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
1482898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
1483898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
1484898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1485898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           (cond->isValueDependent() ||
1486898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
1487898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (rhs && rhs->isValueDependent()))) {
14881237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
14891237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
14901237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
14911237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1493ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
1494ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
1495ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
1496ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1497395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
1498395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
14995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1500ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
1501395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1502395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1503395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
1504395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
1505395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
1506395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1507395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  is only evaluated once.
1508395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
15095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1510395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
1511395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1512395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1513395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
15145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1515395a2abf0028968d85958610e393e067885dc14fTed Kremenek
15165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1517ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1518ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
15195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1520ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ConditionalOperatorClass;
15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
15291237c673c07f9d827129ba02720108816abde562Ted Kremenek
15301237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15311237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15321237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
15335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15356481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
15366481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15406481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
15416481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
15426481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
15457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  explicit AddrLabelExpr(EmptyShell Empty)
15467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
15477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15487d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
15497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
15507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
15517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
15527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
15545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
15587d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
15597d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
15616481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    return T->getStmtClass() == AddrLabelExprClass;
15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15636481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
15641237c673c07f9d827129ba02720108816abde562Ted Kremenek
15651237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15661237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15671237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1569ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1570ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1571ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1572ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
1573ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
15745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
1575ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
1576ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
1577d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
1578d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
1579d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1580ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
15816a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
15826a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
15836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
15845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
15855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
15866a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
15876a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
1588ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
1589ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
1590ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1592026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
15936a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1594026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
15956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1596026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
1597ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
1598ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return T->getStmtClass() == StmtExprClass;
1599ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
1600ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
16011237c673c07f9d827129ba02720108816abde562Ted Kremenek
16021237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16031237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16041237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1605ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
1606ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1607d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1608d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
1609d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
1610d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
1611d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
1612d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
1613d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
1614363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1615d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
1616363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1617d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff                      QualType t1, QualType t2, SourceLocation RP) :
1618d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1619363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    BuiltinLoc(BLoc), RParenLoc(RP) {}
1620d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
162144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
162244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
162344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
162444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
16257f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
162644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
16277f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
162844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
1629ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
163044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
163144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
163244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
163344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
163444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
163544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
1636d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
1637363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1638d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1639d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
1640d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    return T->getStmtClass() == TypesCompatibleExprClass;
1641d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1642d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
16431237c673c07f9d827129ba02720108816abde562Ted Kremenek
16441237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16451237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16461237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1647d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
1648d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
1649d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
1650d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
1651d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
1652d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
1653d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
1654d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
1655d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
1656d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
1657d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1658d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
1659d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
1660d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
1661d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
16625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
1663d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
1664d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1665d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
1666d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1667d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    QualType Type, SourceLocation BLoc,
1668d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    SourceLocation RP) :
1669d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1670f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek    RParenLoc(RP), NumExprs(nexpr) {
1671f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek
16725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    SubExprs = new Stmt*[nexpr];
1673d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
1674d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
1675d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
167694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
167794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
167894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit ShuffleVectorExpr(EmptyShell Empty)
167994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
168094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
168194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
168294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
168394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
168494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
168594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
168694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1687d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
1688d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
1689d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1690d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
1691d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return T->getStmtClass() == ShuffleVectorExprClass;
1692d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1693d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
1694d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1695d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ~ShuffleVectorExpr() {
1696d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    delete [] SubExprs;
1697d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1698d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1699d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1700d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
1701d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
1702d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
1703d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1704d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
1705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
1706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
17075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
1710d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
17115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
171494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setExprs(Expr ** Exprs, unsigned NumExprs);
171594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1716dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1717dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
17189a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
1719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
1722d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
1723d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
1724d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
1725d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1726d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1727d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with
1728d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
17297976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
17307976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
17317976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
17327976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
17337976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
17347976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
1735d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
17361237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
17375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1738d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1739d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
1740d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1741d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff             SourceLocation RP)
1742d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : Expr(ChooseExprClass, t),
17431237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
17441237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
17451237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
17461237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
17471237c673c07f9d827129ba02720108816abde562Ted Kremenek    }
17487976932a1c256d447316ffac58e9821417725e34Eli Friedman
174944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
175044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
175144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
17527976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
17537976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
175427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
17557976932a1c256d447316ffac58e9821417725e34Eli Friedman
17567976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
17577976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
17587976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
17597976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
17607976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
17617976932a1c256d447316ffac58e9821417725e34Eli Friedman
17625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
176344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
17645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
176544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
17665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
176744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
176844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
176944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
177044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
177144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
177244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
177344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
17741237c673c07f9d827129ba02720108816abde562Ted Kremenek
1775d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
1776d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1777d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1778d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
1779d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return T->getStmtClass() == ChooseExprClass;
1780d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1781d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
17821237c673c07f9d827129ba02720108816abde562Ted Kremenek
17831237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17841237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17851237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1786d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
1787d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
17882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
17892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
17902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
17912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
17922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
17932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
17942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
17952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
17962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
17972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
17982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
17992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  GNUNullExpr(QualType Ty, SourceLocation Loc)
18002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
18012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
180244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
180344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
180444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
18052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
18062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
180744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
18082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
18102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
18112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
18122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
18132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return T->getStmtClass() == GNUNullExprClass;
18142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
18152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
18162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
18182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
18192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
18202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
18212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start.
18237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
18245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
18257c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
18267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
18277c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
18287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : Expr(VAArgExprClass, t),
18297c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
18307c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
18317c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
18327c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
1833d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Create an empty __builtin_va_start expression.
1834d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
1835d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
18365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
18375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1838d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1839d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
1840d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1841d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1842d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
1843d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1844d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1845d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
18467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
18477c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
18487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
18497c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
18507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
18517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
18527c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
18537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
18547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
18557c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
18567c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_end();
18577c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
18587c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
18594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
18604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
18614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
18624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
18634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
18644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
18654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
18664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
18674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
1868196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
18704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
18714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
18724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
18734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
18744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
18754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
18764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
1877196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
18794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
18804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
18814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
18824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
18834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
18844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
18853498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
18864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
18874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
18884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
1889196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
18904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
18914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
18924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
18934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
18944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
18954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
189666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
18975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  std::vector<Stmt *> InitExprs;
189866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
1899418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner
19004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
19014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
19024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
19034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
19040bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
19050bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
19060bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
19070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1908a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
1909a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
1910a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
1911a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
191266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
191366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
19144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor               SourceLocation rbraceloc);
1915d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
1916d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
1917d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
191866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
1919c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  unsigned getNumInits() const { return InitExprs.size(); }
192066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
192166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  const Expr* getInit(unsigned Init) const {
1922c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
192466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
192566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
192666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  Expr* getInit(unsigned Init) {
1927c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
192966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
193066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
19319e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  void setInit(unsigned Init, Expr *expr) {
1932c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
19339e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
19349e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
1935c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
1936fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
1937fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  void reserveInits(unsigned NumInits);
1938fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
19394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
19404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
19424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
19434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
19444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
19454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
19464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
19474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
19484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
19494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
19504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
19524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
19534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
19544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *updateInit(unsigned Init, Expr *expr);
1955c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
19560bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
19570bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
19580bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
19590bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
19600bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
19610bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
19620bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
19630bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
19640bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1965c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
1966c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1967b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
1968b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
1969b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
19709e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff
1971d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
1972d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
1973d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
197487fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
197587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
19764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
19774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
19784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
19804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
19814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
19824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1983a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
1984d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void sawArrayRangeDesignator(bool ARD = true) {
1985d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
1986a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
1987a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
198866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
198966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
199066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
199166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
199266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return T->getStmtClass() == InitListExprClass;
199366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
199466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
199566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
199666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
199766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
199866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
19996336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek
20007fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::iterator iterator;
20017fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
20027fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek
20037fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator begin() { return InitExprs.begin(); }
20047fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator end() { return InitExprs.end(); }
20057fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
20067fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
200766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
200866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
200905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
202205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
202305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
202405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
202505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
202705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
202905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2030ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2031ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2032ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2033ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2034ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2039eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
204005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2041eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
204205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2046ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2047ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2048ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2049ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
205005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
205105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
205205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
205305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
205405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2055ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
205605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
2057ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2058eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
2059ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     unsigned NumSubExprs);
206005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2061d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2062d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2063d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2064d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
206505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
206605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
206705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
206805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
206905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
207005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
207105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
207205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
207305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
207405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
207505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
207705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
207805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
208005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
208105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
208205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
208305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
208405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
208505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
208605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
208705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
208805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
208905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
209005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
209105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
209205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
209305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
209405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned RBracketLoc;
209505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
209605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
209705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
209805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
209905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
210005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
210105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
210205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
210305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
210405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
210505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
210605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
210705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
210805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
210905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
211005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
211105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
211205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
211305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
211405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
211505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
211605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
211705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
211805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
211905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
2120ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
2121ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
212205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
212305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
212405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation FieldLoc)
212505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
212605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
212705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
212805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
212905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
213005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
213105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
213205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
213305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
213405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
213505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
213605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
213705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
213805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
213905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
214005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
214105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
214205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
214305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
214405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
214505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
214605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
214705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
214805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
214905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
215005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
215105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
215205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
215305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
215405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
215505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
215605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
215705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
215805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
215905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
216005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
216105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
216205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
216305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
216405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
216505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
216605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
216705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
216805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
216905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
217087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
217187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
217287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
217387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
217487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
217505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
217605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
217705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
217805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
217905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
218005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
218105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
218205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
218305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
218405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
218505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
218605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
218705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
218805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
218905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
219005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
219105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
219205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
219305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
219405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
219505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
219605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
21974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2198d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
2199d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2200d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
2201d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
2202d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
2203d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
22044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
22054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
22064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
22074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
22084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
22094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
221005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
221105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
221205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
221305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
221405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
221505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
2216eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
221705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2218d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
2219d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
222005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
222105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
222205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
222305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
222405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
2225ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
2226ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_end() {
2227ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return Designators + NumDesignators;
2228ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
222905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2230711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2231711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
2232d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setDesignators(const Designator *Desigs, unsigned NumDesigs);
2233d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
223405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
223505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
223605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
223705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
223805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
223905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
224005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2241d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
224205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
224305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
2244eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
2245eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
2246d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
224705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
224805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
224905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getInit() const {
225005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
225105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
225205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
225305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
225405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
225505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
225605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2257d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
2258d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
2259d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
2260d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
2261d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
2262d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2263d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
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    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
2268d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2269d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2270d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
2271d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
2272d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2273d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
2274d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
2275d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2276d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2277ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
2278ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
2279ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  void ExpandDesignator(unsigned Idx, const Designator *First,
2280ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
2281ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
228205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
228305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2284ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  virtual void Destroy(ASTContext &C);
2285ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
228605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
228705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == DesignatedInitExprClass;
228805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
228905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
229005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
229105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
229205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
22933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_end();
22943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
22953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
22963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
22973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
22983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
22991a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
23001a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
23013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
23021a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
23031a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
23043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr {
23053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
23063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  explicit ImplicitValueInitExpr(QualType ty)
23073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    : Expr(ImplicitValueInitExprClass, ty) { }
23083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
2309d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
2310d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
2311d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
2312d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
23133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const Stmt *T) {
23143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
23153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
23163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
23173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
23183498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
23193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
23203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
23213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
23223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
23233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
232405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_end();
232505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
232605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
23274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
23284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
23294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
23304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
2331a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2332a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
2333a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
2334a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2335a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
233673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
233773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
233873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
2339a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
2340a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
2341d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
2342a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
2343a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
2344a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2345a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
2346a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(ExtVectorElementExprClass, ty),
2347d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
2348a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2349d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
2350d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
2351d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
2352d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2353a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
2354a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
2355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
2356d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2357d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
2358d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
2359d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2360d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
2361d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
2362d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2363a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
2364a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
2365a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2366a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
2367a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
2368a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
2369a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2370a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2371a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
2372a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2373a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2374a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
2375a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2376a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2377a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
23782140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
23792140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
23802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
23812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
2382a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const Stmt *T) {
2383a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return T->getStmtClass() == ExtVectorElementExprClass;
2384a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2385a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
2386a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2387a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
2388a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
2389a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
2390a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
2391a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2392a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
239356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
23949c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
23954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
239656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
239756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
2398b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
23994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
2400b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2401b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump    : Expr(BlockExprClass, ty),
2402b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
24039c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
240484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
240584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
240684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
2407d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
240856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
240984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
241084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
241156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
241256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
241356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
241456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
24159c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
24167297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  const Stmt *getBody(ASTContext &C) const { return getBody(); }
24177297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  Stmt *getBody(ASTContext &C) { return getBody(); }
24187297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor
24199c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
242056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
24219c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
24229c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
242356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
242456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
242556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
2426b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
24275b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
2428b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
242984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
2430b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
24314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
24329c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
24334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
24344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
24354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
24374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
24384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
24394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
24409c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
24414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
24424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
24434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
24444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *D;
24454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
24464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool IsByRef;
24474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
24484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
24494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
245094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
245194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
245294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
245394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
245494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
24554eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
24574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
245894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
245994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
246094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
246194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
246294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
24634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
24644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
246694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
246794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
24684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
24694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return T->getStmtClass() == BlockDeclRefExprClass;
24704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
24714eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
24724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24734eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
24744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
24754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
24764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
24774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
24785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
24795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2481