Expr.h revision b648023da23e8b227cdda57a241db4c6f368726b
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"
23b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h"
24c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
27590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
28c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
29c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
31c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
328e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
3588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
3688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
3788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
44898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected:
461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// TypeDependent - Whether this expression is type-dependent
47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ValueDependent - Whether this expression is value-dependent
51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
52898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor should go away and we should
55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // require every subclass to provide type/value-dependence
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // information.
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr(StmtClass SC, QualType T)
58b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    setType(T);
6083233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor  }
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
63b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
670b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Increases the reference count for this expression.
7243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// Invoke the Retain() operation when this expression
7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// is being shared by another owner.
7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  Expr *Retain() {
7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    Stmt::Retain();
7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    return this;
7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  }
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((TR.isNull() || !TR->isReferenceType()) &&
908320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
91f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
9477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValueDependent(bool VD) { ValueDependent = VD; }
1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setTypeDependent(bool TD) { TypeDependent = TD; }
1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
132026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
133026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
13740b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis                              SourceRange &R2) const;
1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
14808ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
14976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
155fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
15686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
15786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_MemberFunction
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
15928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
16053202857c60214d80950a975e6e52aebf30bd16aEli Friedman
16153202857c60214d80950a975e6e52aebf30bd16aEli Friedman  // Same as above, but excluding checks for non-object and void types in C
16253202857c60214d80950a975e6e52aebf30bd16aEli Friedman  isLvalueResult isLvalueInternal(ASTContext &Ctx) const;
1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and if it is a structure or union, does not have any member (including,
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
16944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
17044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
17144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
17244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
177fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
179ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1824f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1835daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
184ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
18586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
18686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_MemberFunction
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
18844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
18944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
19233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
19333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
19638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
19738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
1981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
203590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
204590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
206590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
2078070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
208590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
210c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
211c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
212c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  bool isConstantInitializer(ASTContext &Ctx) const;
2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
2162d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
22094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
22194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
22494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
22594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
22694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
22794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
22894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
23094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
23194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
23294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
23394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
23694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
23794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2386ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
239019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
240019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
241019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2425b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2435b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
2446ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
24545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
24645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
247c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
24851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
24951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
25051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
25151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
252b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
253b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// with link time known address.
2541b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2551b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
256b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it
257b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// also succeeds on stack based, immutable address lvalues.
258b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
259b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman
260efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
261efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
262efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
263efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool isNullPointerConstant(ASTContext &Ctx) const;
264efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
26544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
267102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2694e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
2714e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
2724e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
2734e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* IgnoreParens();
27456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
27556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
27627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
27756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
279ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
280ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
281ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
282ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  const Expr* IgnoreParens() const {
2854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
2864e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
28756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
28856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
28956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
290ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
291ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
292ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
294898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
295898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
296898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
3121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *D;
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
3149e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3159e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
3161a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // FIXME: Eventually, this constructor will go away and all subclasses
3171a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // will have to provide the type- and value-dependent flags.
3188e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
3199e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    Expr(SC, t), D(d), Loc(l) {}
3209e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3211a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
3221a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor              bool VD) :
3231a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor    Expr(SC, t, TD, VD), D(d), Loc(l) {}
3241a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor will go away and all clients
327898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // will have to provide the type- and value-dependent flags.
3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
330898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
332898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
3331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3340b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty declaration reference expression.
3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit DeclRefExpr(EmptyShell Empty)
3360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
3370b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
3388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *getDecl() { return D; }
3398e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  const NamedDecl *getDecl() const { return D; }
340904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  void setDecl(NamedDecl *NewD) { D = NewD; }
341904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
3429e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
3430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3479e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return T->getStmtClass() == DeclRefExprClass ||
3481a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == CXXConditionDeclExprClass ||
3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() == QualifiedDeclRefExprClass;
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
35477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
35577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
358d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
359d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
360227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
361227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
362227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
363227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
364cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor    PrettyFunction
365227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
367227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
368227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
369227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
370227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
372773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson    : Expr(PredefinedExprClass, type, type->isDependentType(),
373773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson           type->isDependentType()), Loc(l), Type(IT) {}
3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
37517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
37717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
37817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
379227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
38017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
38117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
38217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
38317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
38417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
3853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  static std::string ComputeName(ASTContext &Context, IdentType IT,
3863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson                                 const Decl *CurrentDecl);
3873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
388227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
389227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
392227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
393d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
39677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
39777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
398227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
399227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
410a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
4110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IntegerLiteral(EmptyShell Empty)
4130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
4140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
418313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
419313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
420313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
4210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
4220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
43077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
43177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
437c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
440c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
441c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
4450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
4460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
447018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
448c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
4550b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
4560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
4570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
46277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
46377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
46477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
46577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
469525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
470720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  FloatingLiteral(const llvm::APFloat &V, bool isexact,
474720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(isexact), Loc(L) {}
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
47717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit FloatingLiteral(EmptyShell Empty)
47917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
48017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
481c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
48217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
48317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
484720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
48517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
486c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
487da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
488da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
489da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
490da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
49217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
49317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
49417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
4954863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // FIXME: The logic for computing the value of a predefined expr should go
4964863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // into a method here that takes the inner-most code decl (a block, function
4974863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // or objc method) that the expr lives in.  This would allow sema and codegen
4984863db4266d066617a1e5ad7c0f3f28c7995c61bChris Lattner  // to be consistent for things like sizeof(__func__) etc.
4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
50877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
50977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5125d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
5135d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
5145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
5155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
5165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
5175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
5185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
5195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
5205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
5215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
5241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
525cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
526cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
5285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
529cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
530cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
5315d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
5345d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
5355d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5375d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
5385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
5395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
5405d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
5415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
542e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
543e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
544e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
545a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
546c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
547c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
548690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
549690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
5508bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
551690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
552c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
553c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
554c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
555c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
556c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
557c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
562726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
563726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
5642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
56842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
56942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
5722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
5732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
575a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
5762085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static StringLiteral *Create(ASTContext &C, const char *StrData,
5792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
5802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
5812085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
5822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
583a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
584673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
585673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
586673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
587b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  llvm::StringRef getString() const {
588b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return llvm::StringRef(StrData, ByteLength);
589b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
590b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  // FIXME: These are deprecated, replace with StringRef.
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
593673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
594673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
595b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void setString(ASTContext &C, llvm::StringRef Str);
596673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
598673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
599673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
6008d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
601b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    llvm::StringRef Str = getString();
602b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
603b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
60433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
60533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
60633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
607726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
608726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
609726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
612726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
613726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
614726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
616673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
617673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
618673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
619673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
620b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
621b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
622b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
63377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
63477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
6415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
644898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
6451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           val->isTypeDependent(), val->isValueDependent()),
646898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
6471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
648c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
650c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
651c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
6525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
6535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
654c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
655c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
656866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
658313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
659313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
660c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
661313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
662313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
663313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
664c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
665313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
6701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
67177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
67277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
67377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
6780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
680dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
681dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
682dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
683dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
684dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
685dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
686dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
68773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   subexpression is a compound literal with the various MemberExpr and
68973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   ArraySubscriptExpr's applied to it.
69073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
69313d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
70173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
70273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
7055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
7119103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
7129103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           input->isValueDependent()),
7149103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
7180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
7190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
7210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
7220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
7240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
7250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
7280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
7290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
7312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
7322085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
7332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7355a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
7362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
7372085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
7382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
7395a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
7405a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
7425d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
7445a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
752bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
753bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
754bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
755bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
756bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
757bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
758bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
759bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
77477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
77577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
7790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
7800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
7810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
7820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
783d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
784d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    void *Ty;
785d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
786d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
78842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
78942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
79042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
79142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, QualType T,
7940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
7950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
7962850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
797ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
7982850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
799ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           T->isDependentType()),
800ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
801ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
802ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
803ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, Expr *E,
805ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
806ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
807ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
808ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
809ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
810ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
811ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
812ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
813d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
8140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
8150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
8160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
8170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
8180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
8200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
8210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
8230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
8240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
825d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return QualType::getFromOpaquePtr(Argument.Ty);
8260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
827caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
8280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
829d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
8300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
831caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
832caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
833caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
8340b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8350b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setArgument(QualType T) {
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Argument.Ty = T.getAsOpaquePtr();
8381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    isType = true;
8390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
8400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
8420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
8430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
8440518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
8450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
8460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
84776e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
8480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
8490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
8500b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
8510b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
852866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
853866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
854866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
855866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SizeOfAlignOfExprClass;
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
86377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
86477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
87377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8772324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
87873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
8792850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
8802850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
8812850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
8822850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
88373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
88473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
88573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
887cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
888cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
889cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
890cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
8912324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
8922324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
8932324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
8942324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
8952324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
89633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
89733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
89833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
89933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
9005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
9015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
902cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
903cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
9045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
9055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
906cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
9095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
91077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
9135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
9142324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
9175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
9182324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
9215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
92577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
928026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
929cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
930cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
9315cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
93977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
94077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
944b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
946b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
948b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
949b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
95177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
9525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
956b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
957b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
958668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
959668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
96042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
96142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9671f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
968ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
9691f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
970668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
9735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
97418b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
975a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
976a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
977a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
978a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
9905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
993934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
994934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
995934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
996934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
997934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
999d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
1000d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
1001d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
10028189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
10055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1007d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1008d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
10095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
10105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1016cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1017cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
10183c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
10226dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
10236dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1025d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
10261f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1027866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
102977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1033b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    return T->getStmtClass() == CallExprClass ||
103488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXOperatorCallExprClass ||
10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() == CXXMemberCallExprClass;
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
103888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
103988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
104088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
104177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
104277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
104377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \brief Represents the qualifier that may precede a C++ name, e.g., the
104783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor/// "std::" in "std::sort".
104883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregorstruct NameQualifier {
104983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief The nested name specifier.
105083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NestedNameSpecifier *NNS;
10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
105283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief The source range covered by the nested name specifier.
105383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  SourceRange Range;
105483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor};
1055c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1056c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor/// \brief Represents an explicit template argument list in C++, e.g.,
10571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the "<int>" in "sort<int>".
1058c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregorstruct ExplicitTemplateArgumentList {
1059c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief The source location of the left angle bracket ('<');
1060c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  SourceLocation LAngleLoc;
10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1062c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief The source location of the right angle bracket ('>');
1063c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  SourceLocation RAngleLoc;
10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1065c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief The number of template arguments in TemplateArgs.
10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The actual template arguments (if any) are stored after the
1067c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// ExplicitTemplateArgumentList structure.
1068c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  unsigned NumTemplateArgs;
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1070c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments
10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateArgument *getTemplateArgs() {
10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<TemplateArgument *> (this + 1);
1073c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1074c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1075c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments
1076c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const TemplateArgument *getTemplateArgs() const {
10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<const TemplateArgument *> (this + 1);
1078c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1079c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor};
10801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1081ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
1084ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1085ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
10865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1088ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1089ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
109086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *MemberDecl;
10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1092ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1095ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
109683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
109883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// refer to the member, e.g., "x->Base::f". When true, a NameQualifier
1100c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
110183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool HasQualifier : 1;
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1103c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief True if this member expression specified a template argument list
1104c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1105c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure (and its TemplateArguments) are allocated immediately after
1106c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier, after
1107c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the NameQualifier structure.
1108c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  bool HasExplicitTemplateArgumentList : 1;
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
111183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  NameQualifier *getMemberQualifier() {
111283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (!HasQualifier)
111383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return reinterpret_cast<NameQualifier *> (this + 1);
111683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
111783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
111883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
111983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  const NameQualifier *getMemberQualifier() const {
1120c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1121c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1123c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1124c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1125c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1126c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
112783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1129c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasQualifier)
1130c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
11311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1132c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
1133c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                                                      getMemberQualifier() + 1);
1134c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1136c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1137c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1138c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1139c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
114083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
114383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor             SourceRange qualrange, NamedDecl *memberdecl, SourceLocation l,
11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             bool has_explicit, SourceLocation langle,
11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             const TemplateArgument *targs, unsigned numtargs,
11461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             SourceLocation rangle, QualType ty);
114783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
114986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             QualType ty)
11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(MemberExprClass, ty,
1152ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson           base->isTypeDependent(), base->isValueDependent()),
115383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
1154c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      HasQualifier(false), HasExplicitTemplateArgumentList(false) {}
1155510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
11561f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty member reference expression.
11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit MemberExpr(EmptyShell Empty)
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(MemberExprClass, Empty), HasQualifier(false),
1159e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor      HasExplicitTemplateArgumentList(false) { }
11601f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
116283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                            NestedNameSpecifier *qual, SourceRange qualrange,
11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                            NamedDecl *memberdecl,
1164c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation l,
1165c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            bool has_explicit,
1166c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation langle,
1167c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            const TemplateArgument *targs,
1168c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            unsigned numtargs,
1169c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation rangle,
1170c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            QualType ty);
11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
117288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
11735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
117457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
117557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
117657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
117757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
117857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
117986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *getMemberDecl() const { return MemberDecl; }
118088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
11811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
11830979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
11840979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
118583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool hasQualifier() const { return HasQualifier; }
11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
118783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
118883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
118983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// returns an empty source range.
11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getQualifierRange() const {
119183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (!HasQualifier)
119283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return SourceRange();
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
119483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->Range;
119583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
119883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
119983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
120183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    if (!HasQualifier)
120283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->NNS;
120583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
1206c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1207c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
1208c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasExplicitTemplateArgumentList() {
12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return HasExplicitTemplateArgumentList;
1211c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
1214c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member name ('<'), if any.
12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1216c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1217c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1219c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
1220c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1222c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1223c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getTemplateArgs() const {
1225c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1228c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
1229c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1231c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1232c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
1234c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1237c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1238c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
1241c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template arguments ('>').
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
1243c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1244c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1246c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
1247c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
12501f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
12511f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1252ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1253ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1254026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
12551f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
125872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
125972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
1260c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    SourceLocation EndLoc = MemberLoc;
1261c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (HasExplicitTemplateArgumentList)
1262c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      EndLoc = getRAngleLoc();
12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
126472527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
126572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
1266c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceRange(MemberLoc, EndLoc);
1267c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return SourceRange(BaseLoc, EndLoc);
12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
127383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
12761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12771237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
12781237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
12791237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
1283aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1284aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
12850fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
12860fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
12870fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
12880fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
12895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1290e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1291aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
1292a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1293a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                      bool fileScope)
1294a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1295a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner      FileScope(fileScope) {}
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1297ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1298ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1299ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1300ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
13015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
13025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1303ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1304e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1305e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1306ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1307ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
13080fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1309ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1310ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
131173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
13120fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
13130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
13140fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
13150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
131673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
13170fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
131873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1319aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
1322aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1323aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13251237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
13261237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
13271237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1328aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1329aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
133049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
133149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
133249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
133349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
13340835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
1335cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
1336cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  /// CastKind - the kind of cast this represents.
1337cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  enum CastKind {
1338cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_Unknown - Unknown cast kind.
13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// FIXME: The goal is to get rid of this and make all casts have a
1340cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// kind so that the AST client doesn't have to try to figure out what's
1341cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// going on.
1342cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_Unknown,
13431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1344cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_BitCast - Used for reinterpret_cast.
1345cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_BitCast,
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1347cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_NoOp - Used for const_cast.
13483503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    CK_NoOp,
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13503503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    /// CK_DerivedToBase - Derived to base class casts.
1351714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    CK_DerivedToBase,
13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1353714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    /// CK_Dynamic - Dynamic cast.
13544d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    CK_Dynamic,
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13564d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    /// CK_ToUnion - Cast to union (GCC extension).
1357112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    CK_ToUnion,
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1359112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    /// CK_ArrayToPointerDecay - Array to pointer decay.
136027a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_ArrayToPointerDecay,
13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1362b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    // CK_FunctionToPointerDecay - Function to pointer decay.
1363b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    CK_FunctionToPointerDecay,
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136527a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_NullToMemberPointer - Null pointer to member pointer.
136627a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_NullToMemberPointer,
13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136827a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
136927a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// member pointer in derived class.
13709099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian    CK_BaseToDerivedMemberPointer,
13719099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian
13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// CK_UserDefinedConversion - Conversion using a user defined type
137358d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian    /// conversion function.
13747fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    CK_UserDefinedConversion,
13757fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian
13767fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    /// CK_ConstructorConversion - Conversion by constructor
13777f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_ConstructorConversion,
13787f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson
13797f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_IntegralToPointer - Integral to pointer
13807f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_IntegralToPointer,
13817f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson
13827f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_PointerToIntegral - Pointer to integral
13837f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_PointerToIntegral
1384cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  };
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1386cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
1387cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind Kind;
13880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
13890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
1390c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op) :
1391898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1392898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1393898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1394898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1395898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1396898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType() || (op && op->isValueDependent())),
1398c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson    Kind(kind), Op(op) {}
13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1400087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CastExpr(StmtClass SC, EmptyShell Empty)
1402087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
1405cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind getCastKind() const { return Kind; }
1406cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  void setCastKind(CastKind K) { Kind = K; }
1407f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
1408f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
14090835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
14100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1411087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
1412087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14149d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
14159d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
14169d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
14179d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
14186eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
14190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis      return true;
14209d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
14219d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
14220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
14230835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14250835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
14260835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
14270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
14280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
14290835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
143049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
143149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
143249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
143349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
143449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1435bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1436bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1437bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1438bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1439bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1440bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1441bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
1443bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1444bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1445bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
14460835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1447eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1448eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1449eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
145049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1451c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, bool Lvalue) :
1452c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson    CastExpr(ImplicitCastExprClass, ty, kind, op), LvalueCast(Lvalue) { }
145390045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1454087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitCastExpr(EmptyShell Shell)
1456087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
1457087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
1458087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
14590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
14600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
14610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
146290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1463eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1464eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1465eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1466eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1467eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1468eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
147149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
147249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
147349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
147449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
147549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
147749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
147849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
147949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
148049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
148149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
148249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
148449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
148549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
148649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
148749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
148849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
148949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
149049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
14910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
149249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// TypeAsWritten - The type that this expression is casting to, as
149349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// written in the source code.
149449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType TypeAsWritten;
149549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
149649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
1497c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
14981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   Expr *op, QualType writtenTy)
1499c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson    : CastExpr(SC, exprTy, kind, op), TypeAsWritten(writtenTy) {}
150049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
1501db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
15021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1503db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
1504db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
150549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
150649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
150749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
150849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType getTypeAsWritten() const { return TypeAsWritten; }
1509db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
151049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
15129d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
15136eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
15149d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
15159d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
151649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
15179d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
15189d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
151949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
152049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
152149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
152249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
15236eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
152449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
152549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
15266eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
1527b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
1528b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, QualType writtenTy,
15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SourceLocation l, SourceLocation r) :
15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, writtenTy),
1533b2f9e516327310d95840d442416084508f80c183Steve Naroff    LPLoc(l), RPLoc(r) {}
153449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
1535db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CStyleCastExpr(EmptyShell Shell)
1537db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1538db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1539b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
1540db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1541db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
1542b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
1543db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1544db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
1546b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15516eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
15525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15543fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
15553fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
15563fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
15573fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
15583fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
15593fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
15603fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
15613fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
15623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
15633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
15643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
15653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
15663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
15673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
15683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
15693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
15703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
15713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
15735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
157603d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
1577224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
15855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
159617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
159717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
15985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
159917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
160017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
160417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
1605898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
1606898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           lhs->isValueDependent() || rhs->isValueDependent()),
1608898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
16091237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
16101237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1615db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
1617db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1618db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
161917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
1620db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1621db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
16225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
1623db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
1624db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
16255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1626db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
16275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1628db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1629db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
16355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
16365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
16375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1638063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
1639063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
1640063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1641063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
1642063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1643063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
1644063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1645063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
16465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1651f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1652f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1653f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
1654f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1656f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1658f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1659f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
1660f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
16625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
16641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
1666eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == BinaryOperatorClass ||
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           S->getStmtClass() == CompoundAssignOperatorClass;
16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
16701237c673c07f9d827129ba02720108816abde562Ted Kremenek
16711237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16721237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16731237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
16741237c673c07f9d827129ba02720108816abde562Ted Kremenek
16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
167617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
167717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation oploc, bool dead)
167817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
16791237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
16801237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
16815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1682ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
16831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
1684ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
16855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
1694ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
1695ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1698ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
1699ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
170017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
170117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1702ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
1703ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1708ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
1709ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
1710ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
1711ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1712ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
1713ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
1714ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1715ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
1716ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
1717ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1718ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
1719ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
1720ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
17215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
17221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
17245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
17311237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
17325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
173347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
17345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
173547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
173647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                      SourceLocation CLoc, Expr *rhs, QualType t)
1737898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
1738898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
1739898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
1740898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
1741898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (cond->isValueDependent() ||
1743898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
174447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor            (rhs && rhs->isValueDependent()))),
174547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      QuestionLoc(QLoc),
174647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      ColonLoc(CLoc) {
17471237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
17481237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
17491237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
17501237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1752ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
1753ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
1754ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
1755ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
1756395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
1757395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
17585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1759ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
1760395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1761395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1762395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
1763395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
1764395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
1765395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //  is only evaluated once.
1767395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
17685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1769395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1771395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1772395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
17735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
17741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1776ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1777ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
17785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1779ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
178147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
178247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
178347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
178447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
178547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
178647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
17925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17951237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17961237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17971237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18006481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
18016481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
18045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18056481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
18066481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
18076481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18097d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
18117d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
18127d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
18137d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
18147d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
18157d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
18167d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
18177d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
18185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
18237d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
18247d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
18255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
18275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
18291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18301237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
18311237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
18321237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1834ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1835ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1836ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1837ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
1838ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
18395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
1840ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
1841ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
1842d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
1843d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
1844d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18466a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
18476a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
18486a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
18495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
18505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
18516a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
18526a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
1853ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
1854ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
1855ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
18561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1857026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
18586a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1859026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
18606a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
18611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1862ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
1864ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
1865ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18671237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
18681237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
18691237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1870ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
1871ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1872dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
1873d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
1874d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
1875d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
1876d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
1877d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
1878d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
1879363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1880d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType t1, QualType t2, SourceLocation RP) :
1883d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1884363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    BuiltinLoc(BLoc), RParenLoc(RP) {}
1885d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
188644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
188744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
188844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
188944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
18907f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
189144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
18927f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
189344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
189544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
189644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
18971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
189844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
189944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1901d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
1902363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1903d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1904d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
19051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == TypesCompatibleExprClass;
1906d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1907d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19091237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
19101237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
19111237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1912d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
1913d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
1914d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
1915d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
1916d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
1917d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
1918d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
1919d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
1920d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
1921d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
1922d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1923d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
1924d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
1925d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
1926d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
19275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
1928d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
1929d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1930888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected:
19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
1932888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
1933d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
1934a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SourceLocation RP) :
1937d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1938f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek    RParenLoc(RP), NumExprs(nexpr) {
19391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1940a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman    SubExprs = new (C) Stmt*[nexpr];
1941d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
1942d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
1943d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
194494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
194594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
194794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
194894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
194994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
195094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
195294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
195394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
195494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1955d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
1956d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
1957d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1958d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
1960d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1961d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1963888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  ~ShuffleVectorExpr() {}
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1965d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1966d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
1967d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
1968d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1970d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
1971d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
1972d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
19735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1974d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1975d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
1976d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
19775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1978d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1980888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
198194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
1982dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1983dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
19849a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
1985d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1987d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
1988d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
1989d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
1990d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
1991d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1992d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
1994d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
19957976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
19967976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
19977976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
19987976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
19997976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
20007976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
2001d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
20021237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
20035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2004d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2005d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
2006d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2007d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff             SourceLocation RP)
20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(ChooseExprClass, t),
20091237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
20101237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
20111237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
20121237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
20131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
20147976932a1c256d447316ffac58e9821417725e34Eli Friedman
201544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
201644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
201744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
20187976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
20197976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
202027437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
20217976932a1c256d447316ffac58e9821417725e34Eli Friedman
20227976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
20237976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
20247976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
20257976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
20267976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
20277976932a1c256d447316ffac58e9821417725e34Eli Friedman
20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
202944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
20305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
203144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
20325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
203344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
203444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
203544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
203644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
20371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
203844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
203944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
20401237c673c07f9d827129ba02720108816abde562Ted Kremenek
2041d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
2042d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2043d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2044d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
2046d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2047d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20491237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
20501237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
20511237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2052d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
2053d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
20542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
20552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
20562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
20572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
20582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
20592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
20602d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
20612d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
20622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
20632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
20642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
20662d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
20672d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
206844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
206944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
207044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
20712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
20722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
207344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
20742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
20752d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
20762d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
20772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
20782d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
20791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
20802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
20812d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
20842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
20852d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
20862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
20872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
20887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start.
20897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
20905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
20917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
20927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
20937c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
20947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : Expr(VAArgExprClass, t),
20957c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
20967c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
20977c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2099d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Create an empty __builtin_va_start expression.
2100d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2101d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
21025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
21035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
2104d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
2105d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2106d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2107d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2109d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2110d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2111d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
21127c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
21137c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
21157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
21167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
21177c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
21187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
21191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21207c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
21217c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
21221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
21237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
21241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
21264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
21274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
21284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
21294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
21304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
21314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
21324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
21334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
2134196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
21354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
21364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
21374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
21384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
21394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
21404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
21414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
21424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
2143196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
21444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
21454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
21464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
21474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
21484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
21494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
21504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
21513498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
21524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
21534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
21544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
2155196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
21564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
21574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
21584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
21594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
21604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
21614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
216266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
216341ef0c3472a3d09c29bc1792f3d26842f2b8a695Douglas Gregor  // FIXME: Eliminate this vector in favor of ASTContext allocation
21645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  std::vector<Stmt *> InitExprs;
216566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
21684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
21694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
21704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
21710bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
21720bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
21730bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
21740bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2175a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
2176a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
2177a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
2178a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
217966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
218066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
21814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor               SourceLocation rbraceloc);
2182d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2183d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
2184d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2186c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  unsigned getNumInits() const { return InitExprs.size(); }
21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getInit(unsigned Init) const {
2189c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
21904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
219166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getInit(unsigned Init) {
2194c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
21954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
219666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
2199c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
22009e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
22019e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
2202c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
2203fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
2204fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  void reserveInits(unsigned NumInits);
22051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
22074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
22084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
22094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
22104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
22114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
22124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
22134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
22144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
22154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
22164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
22174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
22184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
22194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
22204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
22214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *updateInit(unsigned Init, Expr *expr);
2222c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
22230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
22240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
22250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
22260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
22270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
22280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
22290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
22300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
22310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2232c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
2233c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2234b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
2235b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
2236b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2238d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2239d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2240d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
224187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
224287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
22434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
22444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
22454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
22461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
22474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
22484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
22494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2250a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
22511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
2252d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
2253a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
2254a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
225566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
225666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
22571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
225866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
22591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
226066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
226166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
22621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
226366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
226466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
226566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22677fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::iterator iterator;
22687fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
22691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22707fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator begin() { return InitExprs.begin(); }
22717fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator end() { return InitExprs.end(); }
22727fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
22737fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
227466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
227566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
227605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
227705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
227805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
227905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
228005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
228105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
228205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
228405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
228505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
228605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
228705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
228805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
228905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
229005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
229105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
229205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
229305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
229405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
229505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
229605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2297ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2298ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2300ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2301ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
230205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
230305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
230405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
230505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2306eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
230705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2308eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
230905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
231005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
231105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
231205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2313ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2314ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2315ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2316ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
231705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
231805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
231905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
232005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
232105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2322ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
2324ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2325eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
23269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
23279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
232805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2329d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2330d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2331d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2332d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
233342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
233542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
233605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
233705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
233805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
233905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
234005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
234105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
234205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
234305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
234405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
234505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
234705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
234805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
23491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
235005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
235105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
235205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
235305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
235405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
235505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
235605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
235705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
235805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
235905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
236005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
236105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
236205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
236305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
236405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
23651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
236605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
236705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
236805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
236905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
237005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
237105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
237205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
237305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
237405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
237505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
237605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
237705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
237805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
237905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
238005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
238105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
238205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
238305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
238405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
238505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
238605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
238705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
238805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
238905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
239005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
2391ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
2392ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
239305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
239605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
239705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
239805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
239905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
240005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
240105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
240205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
240405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
240505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
240605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
240705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
240805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
240905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
241005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
241105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
241205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
241405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
241505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
241605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
241705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
241805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
241905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
242005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
242105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
242205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
242305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
242405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
242505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
242605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
242705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
242805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
242905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
243005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
243105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
243205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
243305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
243405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
243505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
243605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
243705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
243805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
243905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
244005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
244187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
244287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
244387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
244487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
244587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
244605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
244705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
244805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
244905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
245005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
245105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
245205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
245305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
245405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
245505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
245605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
245705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
245805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
245905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
246005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
246105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
246205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
246305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
246405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
246505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
246605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
246705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
24684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2469d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
2470d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2471d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
2472d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
2473d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
2474d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
24754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
24764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
24774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
24784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
24794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
24804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
248105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
248205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
248405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
248505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
248605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
2487eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
248805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2489d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
2490d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
249105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
249205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
249305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
249405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
249505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
2496ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
24981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
2499ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
250005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2501711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2502711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
2503d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setDesignators(const Designator *Desigs, unsigned NumDesigs);
2504d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
250505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
250605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
250705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
250805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
250905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
251005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
251105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2512d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
251305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
251405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
2515eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
2516eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
2517d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
251805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
251905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
252105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
252205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
252305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
252405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
252505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
252605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
252705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2528d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
2529d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
2530d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
2531d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
2532d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
2533d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2534d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
2535d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
2536d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2537d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
2538d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
2539d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2540d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2541d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
2542d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
2543d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2544d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
2545d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
2546d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2547d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2548ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
2549ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void ExpandDesignator(unsigned Idx, const Designator *First,
2551ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
2552ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
255305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
255405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
255505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
255705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
255805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
255905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
256005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
256105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
25633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
25643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
25663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
25673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
25681a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
25691a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
25703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
25711a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
25721a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
25731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
25743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
25763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    : Expr(ImplicitValueInitExprClass, ty) { }
25773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
2578d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
2579d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
2580d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
2581d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
25843498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
25853498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
25863498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25873498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
25883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
25893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
25903498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
25923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
25931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
259405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
259505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
25962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
25972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
25982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
25992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
26002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
26012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
26021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected:
26032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual void DoDestroy(ASTContext& C);
26041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
26072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                unsigned numexprs, SourceLocation rparenloc);
26082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
26092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  ~ParenListExpr() {}
26102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
26112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
26122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
26131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
26172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
26182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
26192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
26201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
26222ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
26232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
26242ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
26252ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
262683ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
26271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
26292ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
26302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
26312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual SourceRange getSourceRange() const {
26322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
26331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
26362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
26372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
26381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
26402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_begin();
26412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_end();
26422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
26432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
26441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
26464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
26474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
26484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
2649a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2650a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
2651a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
2652a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2653a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
265473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
265573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
265673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
2657a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
2658a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
2659d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
2660a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
2661a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
2662a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2663a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(ExtVectorElementExprClass, ty),
2665d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
26661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2667d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
2668d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
2669d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
2670d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2671a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
2672a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
2673d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
2674d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2675d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
2676d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
2677d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2678d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
2679d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
2680d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2681a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
2682a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2684a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
2685a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
2686a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
26871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2688a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2689a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
2690a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
26911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2692a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
2693a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2694a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26962140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
26972140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
26982140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
26991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
27011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
2702a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2703a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
27041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2705a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
2706a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
2707a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
2708a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
2709a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2710a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
271156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
27129c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
27134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
271456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
271556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
2716b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
27174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
2718b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(BlockExprClass, ty),
2720b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
27219c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
272284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
272384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
272484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
2725d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
272656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
272784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
272884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
272956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
273056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
273156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
273256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
27339c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
27349c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
273556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
27369c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
27379c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
273856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
273956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
274056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
2741b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
27425b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
2743b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
274484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
2745b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
27461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
27479c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
27484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
27494eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
27524eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
27534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
27544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
27574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
27584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ValueDecl *D;
27604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
27617d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool IsByRef : 1;
27627d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool ConstQualAdded : 1;
27634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
27641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
27657d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian                   bool constAdded = false) :
27667d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef),
27677d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian                                       ConstQualAdded(constAdded) {}
276894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
276994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
277094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
277194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
277294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
27731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
27754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
277694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
277794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
277894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
277994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
278094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
27814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
27821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
278494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
27851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27867d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool isConstQualAdded() const { return ConstQualAdded; }
27877d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setConstQualAdded(bool C) { ConstQualAdded = C; }
278894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
27891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BlockDeclRefExprClass;
27914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
27924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
27931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
27954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
27964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
27974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
27984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
27995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
28005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2802